noti วินัย
This commit is contained in:
parent
9e513d3f1a
commit
ae990c0c5f
21 changed files with 244 additions and 1508 deletions
|
|
@ -10913,7 +10913,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
{
|
||||
try
|
||||
{
|
||||
var orgIdSend = new List<Guid>() { Guid.Parse("08dc31bb-0707-4ce0-82fd-7e76903e9fca"), Guid.Parse("08dc30ee-2be8-40d0-81bf-b3f2f52dc0ad") };
|
||||
var orgIdSend = new List<Guid>() { Guid.Parse("") };
|
||||
var profiles = await _dbContext.Set<Profile>()
|
||||
.Include(x => x.Prefix)
|
||||
.Include(x => x.Gender)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Repositories.MessageQueue;
|
||||
using BMA.EHR.Domain.Models.Discipline;
|
||||
using BMA.EHR.Domain.Models.Retirement;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using BMA.EHR.Application.Requests;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories
|
||||
{
|
||||
|
|
@ -13,33 +18,60 @@ namespace BMA.EHR.Application.Repositories
|
|||
private readonly IDisciplineDbContext _dbDisContext;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
private readonly IConfiguration _configuration;
|
||||
public DisciplineRepository(IApplicationDBContext dbContext,
|
||||
IDisciplineDbContext dbDisContext,
|
||||
NotificationRepository repositoryNoti,
|
||||
IConfiguration configuration,
|
||||
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_dbDisContext = dbDisContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
//เรื่องร้องเรียน
|
||||
public async Task NotifyDisciplineComplaint()
|
||||
{
|
||||
var cronjobNotis = await _dbDisContext.Set<DisciplineComplaint>()
|
||||
.Include(x => x.DisciplineComplaint_Profiles)
|
||||
.Where(x => x.DateNotification != null)
|
||||
.Where(x => x.DateNotification.Value.Date == DateTime.Now.Date)
|
||||
.AsQueryable()
|
||||
.ToListAsync();
|
||||
foreach (var cronjobNoti in cronjobNotis)
|
||||
{
|
||||
await _repositoryNoti.PushNotificationAsync(
|
||||
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
|
||||
var baseAPIOrg = _configuration["API"];
|
||||
var apiUrlOrg = $"{baseAPIOrg}/org/workflow/find/director";
|
||||
var refId = new List<Guid>();
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
|
||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||
{
|
||||
refId = cronjobNoti.DisciplineComplaint_Profiles.Select(x => x.PersonId),
|
||||
});
|
||||
var _result = await _res.Content.ReadAsStringAsync();
|
||||
var org = JsonConvert.DeserializeObject<DirectorRequest>(_result);
|
||||
if (_res.IsSuccessStatusCode)
|
||||
{
|
||||
refId = org.result.Select(x => Guid.Parse(x.id)).ToList();
|
||||
}
|
||||
}
|
||||
await _repositoryNoti.PushNotificationsAsync(
|
||||
refId.ToArray(),
|
||||
$"แจ้งเตือนบันทึกข้อมูลร้องเรียนก่อนวันสิ้นสุดเรื่อง {cronjobNoti.Title}",
|
||||
$"แจ้งเตือนบันทึกข้อมูลร้องเรียนก่อนวันสิ้นสุดเรื่อง {cronjobNoti.Title}"
|
||||
);
|
||||
$"แจ้งเตือนบันทึกข้อมูลร้องเรียนก่อนวันสิ้นสุดเรื่อง {cronjobNoti.Title}",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
|
@ -47,16 +79,39 @@ namespace BMA.EHR.Application.Repositories
|
|||
public async Task NotifyDisciplineInvestigate()
|
||||
{
|
||||
var cronjobNotis = await _dbDisContext.Set<DisciplineInvestigate>()
|
||||
.Include(x => x.DisciplineInvestigate_ProfileComplaints)
|
||||
.Where(x => x.InvestigationDateEnd != null && x.InvestigationDateEnd.Value.Date.AddDays(-7) == DateTime.Now.Date)
|
||||
.AsQueryable()
|
||||
.ToListAsync();
|
||||
foreach (var cronjobNoti in cronjobNotis)
|
||||
{
|
||||
await _repositoryNoti.PushNotificationAsync(
|
||||
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
|
||||
var baseAPIOrg = _configuration["API"];
|
||||
var apiUrlOrg = $"{baseAPIOrg}/org/workflow/find/director";
|
||||
var refId = new List<Guid>();
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
|
||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||
{
|
||||
refId = cronjobNoti.DisciplineInvestigate_ProfileComplaints.Select(x => x.PersonId),
|
||||
});
|
||||
var _result = await _res.Content.ReadAsStringAsync();
|
||||
var org = JsonConvert.DeserializeObject<DirectorRequest>(_result);
|
||||
if (_res.IsSuccessStatusCode)
|
||||
{
|
||||
refId = org.result.Select(x => Guid.Parse(x.id)).ToList();
|
||||
}
|
||||
}
|
||||
await _repositoryNoti.PushNotificationsAsync(
|
||||
refId.ToArray(),
|
||||
$"แจ้งเตือนบันทึกข้อมูลสืบสวนก่อนวันสิ้นสุดเรื่อง {cronjobNoti.Title}",
|
||||
$"แจ้งเตือนบันทึกข้อมูลสืบสวนก่อนวันสิ้นสุดเรื่อง {cronjobNoti.Title}"
|
||||
);
|
||||
$"แจ้งเตือนบันทึกข้อมูลสืบสวนก่อนวันสิ้นสุดเรื่อง {cronjobNoti.Title}",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
true
|
||||
);
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
|
@ -65,16 +120,39 @@ namespace BMA.EHR.Application.Repositories
|
|||
public async Task NotifyDisciplineDisciplinary()
|
||||
{
|
||||
var cronjobNotis = await _dbDisContext.Set<DisciplineDisciplinary>()
|
||||
.Include(x => x.DisciplineDisciplinary_ProfileComplaintInvestigates)
|
||||
.Where(x => x.DisciplinaryDateEnd != null && x.DisciplinaryDateEnd.Value.Date.AddDays(-7) == DateTime.Now.Date)
|
||||
.AsQueryable()
|
||||
.ToListAsync();
|
||||
foreach (var cronjobNoti in cronjobNotis)
|
||||
{
|
||||
await _repositoryNoti.PushNotificationAsync(
|
||||
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
|
||||
var baseAPIOrg = _configuration["API"];
|
||||
var apiUrlOrg = $"{baseAPIOrg}/org/workflow/find/director";
|
||||
var refId = new List<Guid>();
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
|
||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
||||
{
|
||||
refId = cronjobNoti.DisciplineDisciplinary_ProfileComplaintInvestigates.Select(x => x.PersonId),
|
||||
});
|
||||
var _result = await _res.Content.ReadAsStringAsync();
|
||||
var org = JsonConvert.DeserializeObject<DirectorRequest>(_result);
|
||||
if (_res.IsSuccessStatusCode)
|
||||
{
|
||||
refId = org.result.Select(x => Guid.Parse(x.id)).ToList();
|
||||
}
|
||||
}
|
||||
await _repositoryNoti.PushNotificationsAsync(
|
||||
refId.ToArray(),
|
||||
$"แจ้งเตือนบันทึกข้อมูลสอบสวนก่อนวันสิ้นสุดเรื่อง {cronjobNoti.Title}",
|
||||
$"แจ้งเตือนบันทึกข้อมูลสอบสวนก่อนวันสิ้นสุดเรื่อง {cronjobNoti.Title}"
|
||||
);
|
||||
$"แจ้งเตือนบันทึกข้อมูลสอบสวนก่อนวันสิ้นสุดเรื่อง {cronjobNoti.Title}",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
true
|
||||
);
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,49 +104,6 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
_appContext.Set<Notification>().Add(noti);
|
||||
await _appContext.SaveChangesAsync();
|
||||
|
||||
|
||||
//var profile_id = profile == null ? Guid.Empty : profile.Id;
|
||||
|
||||
//var rootOc = _userProfileRepository.GetRootOcId(profile_id, AccessToken);
|
||||
//var approver = string.Empty;
|
||||
//var list = new List<OrganizationApproverResponse>();
|
||||
//if (rootOc != null)
|
||||
//{
|
||||
// list = await _commandRepository.GetOrgApproverAsync(rootOc ?? Guid.Empty);
|
||||
//}
|
||||
//if (list.Count > 0)
|
||||
//{
|
||||
// var appr = list.FirstOrDefault();
|
||||
|
||||
// // send inbox and notification
|
||||
// var subject_str = $"มีการขออนุมัติลงเวลากรณีพิเศษ";
|
||||
// var body_str = $"โปรดพิจารณาคำร้องขอลงเวลาในกรณีพิเศษจาก {profile.Prefix}{profile.FirstName} {profile.LastName} ในวันที่ {entity.CheckDate.Date.ToThaiShortDate2()}";
|
||||
|
||||
// var subject = subject_str;
|
||||
// var body = body_str;
|
||||
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
||||
|
||||
|
||||
// var inbox = new Inbox
|
||||
// {
|
||||
// Subject = subject_str,
|
||||
// Body = body_str,
|
||||
// ReceiverUserId = appr.Id == Guid.Empty ? Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6") : appr.Id,
|
||||
// Payload = "",
|
||||
// };
|
||||
// _appContext.Set<Inbox>().Add(inbox);
|
||||
|
||||
// var noti = new Notification
|
||||
// {
|
||||
// Body = body_str,
|
||||
// ReceiverUserId = appr.Id == Guid.Empty ? Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6") : appr.Id,
|
||||
// Type = "",
|
||||
// Payload = "",
|
||||
// };
|
||||
// _appContext.Set<Notification>().Add(noti);
|
||||
// await _appContext.SaveChangesAsync();
|
||||
//}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -369,7 +369,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
|
|||
if (_res.IsSuccessStatusCode)
|
||||
{
|
||||
var org = JsonConvert.DeserializeObject<ResultRequest>(_result);
|
||||
if (org != null && org.result != null)
|
||||
if (org != null && org.result != null && org.result != "")
|
||||
_emailSenderService.SendMail(Subject, Body, org.result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,24 +251,6 @@ namespace BMA.EHR.Application.Repositories.Reports
|
|||
p.posMasterNo,
|
||||
p.posLevelName,
|
||||
p.posTypeName,
|
||||
|
||||
// ProfileId = p.Profile.Id,
|
||||
// Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
|
||||
// PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
|
||||
// p.Profile.FirstName,
|
||||
// p.Profile.LastName,
|
||||
// Position = p.Profile.Position == null ? null : p.Profile.Position.Name,
|
||||
// PositionId = p.Profile.Position == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Position.Id,
|
||||
// PositionType = p.Profile.PositionType == null ? null : p.Profile.PositionType.Name,
|
||||
// PositionTypeId = p.Profile.PositionType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.PositionType.Id,
|
||||
// p.Profile.PositionLine,
|
||||
// p.Profile.PositionLineId,
|
||||
// PositionLevel = p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name,
|
||||
// PositionLevelId = p.Profile.PositionLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.PositionLevel.Id,
|
||||
// p.Profile.PositionExecutive,
|
||||
// p.Profile.PositionExecutiveId,
|
||||
// Organization = p.Profile.Oc,
|
||||
// OrganizationId = p.Profile.OcId,
|
||||
p.position,
|
||||
p.Number,
|
||||
p.Date,
|
||||
|
|
|
|||
|
|
@ -49,11 +49,6 @@ namespace BMA.EHR.Application.Repositories
|
|||
cronjobNoti.Profile.IsLeave = true;
|
||||
cronjobNoti.Profile.LeaveReason = "DISCHARGE";
|
||||
cronjobNoti.Profile.LeaveDate = DateTime.Now;
|
||||
// await _repositoryNoti.PushNotificationAsync(
|
||||
// Guid.Parse("08db721d-ada0-4e64-89d3-7584a893d8b8"),
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}",
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}"
|
||||
// );
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
|
@ -72,11 +67,6 @@ namespace BMA.EHR.Application.Repositories
|
|||
cronjobNoti.Profile.IsLeave = true;
|
||||
cronjobNoti.Profile.LeaveReason = "DISMISS";
|
||||
cronjobNoti.Profile.LeaveDate = DateTime.Now;
|
||||
// await _repositoryNoti.PushNotificationAsync(
|
||||
// Guid.Parse("08db721d-ada0-4e64-89d3-7584a893d8b8"),
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}",
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}"
|
||||
// );
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
|
@ -90,17 +80,6 @@ namespace BMA.EHR.Application.Repositories
|
|||
.Where(x => x.Date != null && x.Date.Value.Date == DateTime.Now.Date)
|
||||
.AsQueryable()
|
||||
.ToListAsync();
|
||||
foreach (var cronjobNoti in cronjobNotis)
|
||||
{
|
||||
//cronjobNoti.Profile.IsLeave = true;
|
||||
//cronjobNoti.Profile.LeaveReason = "LAYOFF";
|
||||
//cronjobNoti.Profile.LeaveDate = DateTime.Now;
|
||||
// await _repositoryNoti.PushNotificationAsync(
|
||||
// Guid.Parse("08db721d-ada0-4e64-89d3-7584a893d8b8"),
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}",
|
||||
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}"
|
||||
// );
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
|
|
|||
13
BMA.EHR.Application/Requests/DirectorRequest.cs
Normal file
13
BMA.EHR.Application/Requests/DirectorRequest.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Application.Requests
|
||||
{
|
||||
public class DirectorRequest
|
||||
{
|
||||
public DirectorRequestData[] result { get; set; }
|
||||
}
|
||||
public class DirectorRequestData
|
||||
{
|
||||
public string id { get; set; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue