no message
This commit is contained in:
parent
2a17eff17d
commit
fb6a83b36a
11 changed files with 17862 additions and 70 deletions
|
|
@ -41,17 +41,17 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
|
|||
{
|
||||
try
|
||||
{
|
||||
var profile = await _dbContext.Set<Profile>()
|
||||
.FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
|
||||
// var profile = await _dbContext.Set<Profile>()
|
||||
// .FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
|
||||
|
||||
if (profile == null)
|
||||
{
|
||||
return new List<NotificationResponse>();
|
||||
// throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
// if (profile == null)
|
||||
// {
|
||||
// return new List<NotificationResponse>();
|
||||
// // throw new Exception(GlobalMessages.DataNotFound);
|
||||
// }
|
||||
|
||||
var data_search = await _dbContext.Set<Notification>()
|
||||
.Where(x => x.ReceiverUserId == profile.Id)
|
||||
.Where(x => x.KeycloakUserId == UserId)
|
||||
.Where(x => x.DeleteDate == null)
|
||||
.OrderByDescending(x => x.ReceiveDate)
|
||||
.ToListAsync();
|
||||
|
|
@ -64,6 +64,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
|
|||
Id = x.Id,
|
||||
Body = x.Body,
|
||||
ReceiverUserId = x.ReceiverUserId,
|
||||
KeycloakUserId = x.KeycloakUserId,
|
||||
IsOpen = x.IsOpen,
|
||||
Type = x.Type,
|
||||
ReceiveDate = x.ReceiveDate,
|
||||
|
|
@ -72,7 +73,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
|
|||
}).ToList();
|
||||
|
||||
var data_opens = await _dbContext.Set<Notification>()
|
||||
.Where(x => x.ReceiverUserId == profile.Id)
|
||||
.Where(x => x.KeycloakUserId == UserId)
|
||||
.Where(x => x.DeleteDate == null)
|
||||
.OrderByDescending(x => x.ReceiveDate)
|
||||
.Skip((page - 1) * pageSize)
|
||||
|
|
@ -99,16 +100,16 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
|
|||
{
|
||||
try
|
||||
{
|
||||
var profile = await _dbContext.Set<Profile>()
|
||||
.FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
|
||||
// var profile = await _dbContext.Set<Profile>()
|
||||
// .FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
|
||||
|
||||
if (profile == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// if (profile == null)
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
var data_search = await _dbContext.Set<Notification>()
|
||||
.Where(x => x.ReceiverUserId == profile.Id)
|
||||
.Where(x => x.KeycloakUserId == UserId)
|
||||
.Where(x => x.DeleteDate == null)
|
||||
.Where(x => x.IsOpen == false)
|
||||
.OrderByDescending(x => x.ReceiveDate)
|
||||
|
|
@ -190,6 +191,53 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
|
|||
throw;
|
||||
}
|
||||
}
|
||||
public async Task PushNotificationAsyncV2(string? ReceiverUserId, string Subject, string Body, string Payload = "", bool IsSendInbox = false, bool IsSendMail = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ReceiverUserId != null)
|
||||
{
|
||||
_dbContext.Set<Notification>().Add(new Notification
|
||||
{
|
||||
Body = Body,
|
||||
KeycloakUserId = ReceiverUserId,
|
||||
Type = "",
|
||||
Payload = Payload,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
if (IsSendInbox == true)
|
||||
{
|
||||
_dbContext.Set<Inbox>().Add(new Inbox
|
||||
{
|
||||
Subject = Subject,
|
||||
Body = Body,
|
||||
KeycloakUserId = ReceiverUserId,
|
||||
Payload = Payload,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
}
|
||||
if (IsSendMail == true)
|
||||
{
|
||||
_emailSenderService.SendMail(Subject, Body, "kittapath@frappet.com");
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
public Guid ReceiverUserId { get; set; } = Guid.Empty;
|
||||
|
||||
public string KeycloakUserId { get; set; }
|
||||
|
||||
public string Type { get; set; } = "TEXT";
|
||||
|
||||
public CommandPayload Payload { get; set; } = new();
|
||||
|
|
|
|||
|
|
@ -13,9 +13,11 @@ namespace BMA.EHR.Domain.Models.Notifications
|
|||
[Required, Column(TypeName = "text"), Comment("รายละเอียดข้อความ")]
|
||||
public string Body { get; set; }
|
||||
|
||||
[Required, Comment("รหัสผู้รับข้อความ")]
|
||||
[Comment("รหัสผู้รับข้อความ")]
|
||||
public Guid ReceiverUserId { get; set; }
|
||||
|
||||
public string KeycloakUserId { get; set; }
|
||||
|
||||
[Column(TypeName = "text"), Comment("สิงที่แนบมาด้วย")]
|
||||
public string Payload { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ namespace BMA.EHR.Domain.Models.Notifications
|
|||
[Required, Column(TypeName = "text"), Comment("รายละเอียดข้อความ")]
|
||||
public string Body { get; set; }
|
||||
|
||||
[Required, Comment("รหัสผู้รับข้อความ")]
|
||||
[Comment("รหัสผู้รับข้อความ")]
|
||||
public Guid ReceiverUserId { get; set; }
|
||||
|
||||
public string KeycloakUserId { get; set; }
|
||||
|
||||
[Required, Comment("ประเภทการแจ้งเตือน")]
|
||||
public string Type { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ namespace BMA.EHR.Domain.Models.Retirement
|
|||
{
|
||||
public class RetirementDeceasedNoti : EntityBase
|
||||
{
|
||||
// [Comment("รหัสอ้างอิงผู้ใช้งานระบบ")]
|
||||
// public Profile ReceiveUser { get; set; }
|
||||
[Comment("profile Id")]
|
||||
public string? profileId { get; set; }
|
||||
[Comment("Fk Table RetirementDeceased")]
|
||||
public RetirementDeceased RetirementDeceased { get; set; }
|
||||
|
||||
|
|
|
|||
17652
BMA.EHR.Infrastructure/Migrations/20240521044624_update table Notification add KeycloakUserId.Designer.cs
generated
Normal file
17652
BMA.EHR.Infrastructure/Migrations/20240521044624_update table Notification add KeycloakUserId.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,52 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BMA.EHR.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class updatetableNotificationaddKeycloakUserId : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "profileId",
|
||||
table: "RetirementDeceasedNotis",
|
||||
type: "longtext",
|
||||
nullable: true,
|
||||
comment: "profile Id")
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "KeycloakUserId",
|
||||
table: "Notifications",
|
||||
type: "longtext",
|
||||
nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "KeycloakUserId",
|
||||
table: "Inboxes",
|
||||
type: "longtext",
|
||||
nullable: false)
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "profileId",
|
||||
table: "RetirementDeceasedNotis");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "KeycloakUserId",
|
||||
table: "Notifications");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "KeycloakUserId",
|
||||
table: "Inboxes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9250,6 +9250,10 @@ namespace BMA.EHR.Infrastructure.Migrations
|
|||
.HasColumnType("tinyint(1)")
|
||||
.HasComment("เปิดอ่านแล้วหรือยัง");
|
||||
|
||||
b.Property<string>("KeycloakUserId")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("LastUpdateFullName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
|
|
@ -9438,6 +9442,10 @@ namespace BMA.EHR.Infrastructure.Migrations
|
|||
.HasColumnType("tinyint(1)")
|
||||
.HasComment("เปิดอ่านแล้วหรือยัง");
|
||||
|
||||
b.Property<string>("KeycloakUserId")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("LastUpdateFullName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
|
|
@ -14158,6 +14166,10 @@ namespace BMA.EHR.Infrastructure.Migrations
|
|||
b.Property<Guid>("RetirementDeceasedId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<string>("profileId")
|
||||
.HasColumnType("longtext")
|
||||
.HasComment("profile Id");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DocumentId");
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
IsSendNotification = true,
|
||||
// OrganizationName = retirementDeceased.OrganizationName,
|
||||
PositionName = retirementDeceased.position,
|
||||
// ReceiveUser = profile,
|
||||
profileId = req.ProfileId,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
|
|
@ -502,7 +502,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
p.IsSendNotification,
|
||||
p.OrganizationName,
|
||||
p.PositionName,
|
||||
// ProfileId = p.ReceiveUser.Id,
|
||||
p.profileId,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
|
|
@ -529,32 +529,53 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
|
||||
foreach (var item in req.Persons)
|
||||
{
|
||||
var profile = await _context.Profiles.AsQueryable()
|
||||
.Include(x => x.Prefix)
|
||||
.Include(x => x.Position)
|
||||
.FirstOrDefaultAsync(x => x.Id == item.ProfileId);
|
||||
if (profile == null)
|
||||
continue;
|
||||
|
||||
retirementDeceased.RetirementDeceasedNotis.Add(new RetirementDeceasedNoti
|
||||
// var profile = await _context.Profiles.AsQueryable()
|
||||
// .Include(x => x.Prefix)
|
||||
// .Include(x => x.Position)
|
||||
// .FirstOrDefaultAsync(x => x.Id == item.ProfileId);
|
||||
// if (profile == null)
|
||||
// continue;
|
||||
var retirementDeceasedNoti = new RetirementDeceasedNoti
|
||||
{
|
||||
CitizenId = profile.CitizenId == null ? "" : profile.CitizenId,
|
||||
Prefix = profile.Prefix == null ? "" : profile.Prefix.Name,
|
||||
FirstName = profile.FirstName == null ? "" : profile.FirstName,
|
||||
LastName = profile.LastName == null ? "" : profile.LastName,
|
||||
profileId = item.ProfileId,
|
||||
IsSendMail = item.IsSendMail,
|
||||
IsSendInbox = item.IsSendInbox,
|
||||
IsSendNotification = item.IsSendNotification,
|
||||
OrganizationName = profile.OrganizationOrganization == null ? "" : profile.OrganizationOrganization,
|
||||
PositionName = profile.Position == null ? null : profile.Position.Name,
|
||||
// ReceiveUser = profile,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
};
|
||||
|
||||
var apiUrl = $"{_configuration["API"]}org/profile/profileid/position/{item.ProfileId}";
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
||||
var _res = await client.SendAsync(_req);
|
||||
var _result = await _res.Content.ReadAsStringAsync();
|
||||
|
||||
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
|
||||
|
||||
if (org == null || org.result == null)
|
||||
continue;
|
||||
|
||||
retirementDeceasedNoti.Prefix = org.result.prefix == null ? "" : org.result.prefix;
|
||||
retirementDeceasedNoti.FirstName = org.result.firstName == null ? "" : org.result.firstName;
|
||||
retirementDeceasedNoti.LastName = org.result.lastName == null ? "" : org.result.lastName;
|
||||
retirementDeceasedNoti.CitizenId = org.result.citizenId == null ? "" : org.result.citizenId;
|
||||
retirementDeceasedNoti.PositionName = org.result.position == null ? "" : org.result.position;
|
||||
retirementDeceasedNoti.OrganizationName = (org.result.child4 == null ? "" : org.result.child4 + "/") +
|
||||
(org.result.child3 == null ? "" : org.result.child3 + "/") +
|
||||
(org.result.child2 == null ? "" : org.result.child2 + "/") +
|
||||
(org.result.child1 == null ? "" : org.result.child1 + "/") +
|
||||
(org.result.root == null ? "" : org.result.root + "/");
|
||||
}
|
||||
|
||||
retirementDeceased.RetirementDeceasedNotis.Add(retirementDeceasedNoti);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
|
@ -625,36 +646,37 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
};
|
||||
|
||||
var payload_str = JsonConvert.SerializeObject(payload);
|
||||
// foreach (var item in items)
|
||||
// {
|
||||
// var prefix = item.RetirementDeceased.prefix;
|
||||
// var profile = req.Persons.FirstOrDefault(x => x.ProfileId == item.ReceiveUser.Id);
|
||||
// if (profile != null)
|
||||
// {
|
||||
// await _repositoryNoti.PushNotificationAsync(
|
||||
// item.ReceiveUser.Id,
|
||||
// $"หนังสือเวียนถึงแก่กรรมของ {prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
|
||||
// $"แจ้งข่าวการถึงแก่กรรมของ {prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
|
||||
// payload_str,
|
||||
// profile.IsSendInbox,
|
||||
// profile.IsSendMail
|
||||
// );
|
||||
// item.IsSendMail = profile.IsSendMail;
|
||||
// item.IsSendInbox = profile.IsSendInbox;
|
||||
// item.IsSendNotification = profile.IsSendNotification;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// await _repositoryNoti.PushNotificationAsync(
|
||||
// item.ReceiveUser.Id,
|
||||
// $"หนังสือเวียนถึงแก่กรรมของ {prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
|
||||
// $"แจ้งข่าวการถึงแก่กรรมของ {prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
|
||||
// payload_str,
|
||||
// item.IsSendInbox,
|
||||
// item.IsSendMail
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
foreach (var item in items)
|
||||
{
|
||||
// var profile = item.profileId;
|
||||
// var prefix = item.profileId;
|
||||
var profile = req.Persons.FirstOrDefault(x => x.ProfileId == item.profileId);
|
||||
if (profile != null)
|
||||
{
|
||||
await _repositoryNoti.PushNotificationAsyncV2(
|
||||
item.profileId,
|
||||
$"หนังสือเวียนถึงแก่กรรมของ {item.RetirementDeceased.prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
|
||||
$"แจ้งข่าวการถึงแก่กรรมของ {item.RetirementDeceased.prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
|
||||
payload_str,
|
||||
profile.IsSendInbox,
|
||||
profile.IsSendMail
|
||||
);
|
||||
item.IsSendMail = profile.IsSendMail;
|
||||
item.IsSendInbox = profile.IsSendInbox;
|
||||
item.IsSendNotification = profile.IsSendNotification;
|
||||
}
|
||||
else
|
||||
{
|
||||
await _repositoryNoti.PushNotificationAsyncV2(
|
||||
item.profileId,
|
||||
$"หนังสือเวียนถึงแก่กรรมของ {item.RetirementDeceased.prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
|
||||
$"แจ้งข่าวการถึงแก่กรรมของ {item.RetirementDeceased.prefix}{item.RetirementDeceased.firstName} {item.RetirementDeceased.lastName}",
|
||||
payload_str,
|
||||
item.IsSendInbox,
|
||||
item.IsSendMail
|
||||
);
|
||||
}
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace BMA.EHR.Retirement.Service.Requests
|
|||
}
|
||||
public class RetirementDeceasedAddNotiPerson
|
||||
{
|
||||
public Guid ProfileId { get; set; }
|
||||
public string ProfileId { get; set; }
|
||||
public bool IsSendMail { get; set; } = true;
|
||||
public bool IsSendInbox { get; set; } = true;
|
||||
public bool IsSendNotification { get; set; } = true;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@ namespace BMA.EHR.Retirement.Service.Requests
|
|||
public DateTime? Date { get; set; }
|
||||
public string? Location { get; set; }
|
||||
public string? Reason { get; set; }
|
||||
public Guid ProfileId { get; set; }
|
||||
public string ProfileId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue