diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index b6d18618..eeb4675e 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -1,5 +1,4 @@ -using Amazon; -using BMA.EHR.Application.Common.Interfaces; +using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Application.Messaging; using BMA.EHR.Application.Requests.Commands; using BMA.EHR.Application.Responses; @@ -17,9 +16,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; -using System.Drawing; using System.Net.Http.Headers; -using System.Security.Cryptography; using Command = BMA.EHR.Domain.Models.Commands.Core.Command; using Profile = BMA.EHR.Domain.Models.HR.Profile; @@ -1536,6 +1533,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + // create new profile foreach (var recv in command.Receivers) { @@ -1838,7 +1851,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คุณได้รับบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -1846,8 +1859,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คุณได้รับบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -1868,7 +1881,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งบบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -1887,8 +1900,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งบบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -1915,6 +1928,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var placementProfile = await _dbContext.Set() @@ -1970,7 +1999,7 @@ namespace BMA.EHR.Application.Repositories.Commands var profile = await _dbContext.Set() .Include(x => x.Salaries) .FirstOrDefaultAsync(x => x.CitizenId == placementProfile.CitizenId); - if(profile != null) + if (profile != null) { profile.Position = placementProfile.PositionPath; profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; @@ -2071,7 +2100,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -2079,8 +2108,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -2099,7 +2128,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -2118,8 +2147,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -2146,6 +2175,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var placementProfile = await _dbContext.Set() @@ -2302,7 +2347,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -2310,8 +2355,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -2330,7 +2375,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -2349,8 +2394,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -2377,6 +2422,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var placementProfile = await _dbContext.Set() @@ -2514,7 +2575,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -2522,8 +2583,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -2542,7 +2603,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -2561,8 +2622,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -2589,6 +2650,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var placementProfile = await _dbContext.Set() @@ -2726,7 +2803,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -2734,8 +2811,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -2754,7 +2831,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -2773,8 +2850,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -2801,6 +2878,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var placementProfile = await _dbContext.Set() @@ -2938,7 +3031,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -2946,8 +3039,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -2966,7 +3059,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -2985,8 +3078,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -3013,12 +3106,41 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var placementProfile = await _dbContext.Set() .Include(x => x.Profile) .ThenInclude(x => x.Salaries) + //.Include(x => x.Profile) + //.ThenInclude(x => x.Position) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PositionPathSide) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PositionType) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PositionLine) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PositionLevel) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PosNo) + .Include(x => x.PositionPath) .Include(x => x.PositionPathSide) .Include(x => x.PositionType) @@ -3054,23 +3176,23 @@ namespace BMA.EHR.Application.Repositories.Commands profile.IsActive = true; profile.IsLeave = false; profile.LeaveDate = null; - - profile.Position = placementProfile.PositionPath; - profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; - profile.PositionType = placementProfile.PositionType; - profile.PositionLevel = placementProfile.PositionLevel; - profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id; - profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name; - profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber; + //profile.Position = placementProfile.Profile.Position; + //profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; + //profile.PositionType = placementProfile.PositionType; + //profile.PositionLevel = placementProfile.PositionLevel; + + //profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id; + //profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name; + //profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber; // organization - profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id; - profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name; - profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id; - profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id; - profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"); + //profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id; + //profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name; + //profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id; + //profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id; + //profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"); } var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); @@ -3078,16 +3200,7 @@ namespace BMA.EHR.Application.Repositories.Commands if (lastSarary.Order != null) order = lastSarary.Order.Value + 1; - var oc = _dbContext.Set() - .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id); - - var position = placementProfile.PositionPath; - - var positionNumber = placementProfile.PositionNumber; - - var positionType = placementProfile.PositionType; - - var positionLevel = placementProfile.PositionLevel; + var salary = new ProfileSalary { @@ -3100,13 +3213,13 @@ namespace BMA.EHR.Application.Repositories.Commands SalaryClass = "", SalaryRef = "คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", - OcId = oc == null ? Guid.Empty : oc.Id, + OcId = lastSarary.OcId, - PositionLevel = placementProfile.PositionLevel, - PositionLineId = placementProfile.PositionLine!.Id, - PositionTypeId = placementProfile.PositionType!.Id, - OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, - PosNoId = positionNumber!.Id, + PositionLevel = lastSarary.PositionLevel, + PositionLineId = lastSarary.PositionLineId, + PositionTypeId = lastSarary.PositionTypeId, + OrganizationShortNameId = lastSarary.OrganizationShortNameId, + PosNoId = lastSarary.PosNoId, CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", CommandTypeName = command.CommandType.Name, @@ -3119,8 +3232,8 @@ namespace BMA.EHR.Application.Repositories.Commands PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id, - PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, - PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, + PositionExecutiveId = placementProfile.OrganizationPosition == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, + PositionExecutiveSideId = placementProfile.OrganizationPosition == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, IsActive = true, @@ -3155,7 +3268,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -3163,8 +3276,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -3183,7 +3296,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -3202,8 +3315,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -3230,12 +3343,41 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var placementProfile = await _dbContext.Set() .Include(x => x.Profile) .ThenInclude(x => x.Salaries) + //.Include(x => x.Profile) + //.ThenInclude(x => x.Position) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PositionPathSide) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PositionType) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PositionLine) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PositionLevel) + //.Include(x => x.Profile) + //.ThenInclude(x => x.PosNo) + .Include(x => x.PositionPath) .Include(x => x.PositionPathSide) .Include(x => x.PositionType) @@ -3273,21 +3415,21 @@ namespace BMA.EHR.Application.Repositories.Commands profile.LeaveDate = null; - profile.Position = placementProfile.PositionPath; - profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; - profile.PositionType = placementProfile.PositionType; - profile.PositionLevel = placementProfile.PositionLevel; + //profile.Position = placementProfile.PositionPath; + //profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; + //profile.PositionType = placementProfile.PositionType; + //profile.PositionLevel = placementProfile.PositionLevel; - profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id; - profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name; - profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber; + //profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id; + //profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name; + //profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber; - // organization - profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id; - profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name; - profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id; - profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id; - profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"); + //// organization + //profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id; + //profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name; + //profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id; + //profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id; + //profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"); } var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); @@ -3295,16 +3437,16 @@ namespace BMA.EHR.Application.Repositories.Commands if (lastSarary.Order != null) order = lastSarary.Order.Value + 1; - var oc = _dbContext.Set() - .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id); + //var oc = _dbContext.Set() + // .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id); - var position = placementProfile.PositionPath; + //var position = placementProfile.PositionPath; - var positionNumber = placementProfile.PositionNumber; + //var positionNumber = placementProfile.PositionNumber; - var positionType = placementProfile.PositionType; + //var positionType = placementProfile.PositionType; - var positionLevel = placementProfile.PositionLevel; + //var positionLevel = placementProfile.PositionLevel; var salary = new ProfileSalary { @@ -3317,13 +3459,13 @@ namespace BMA.EHR.Application.Repositories.Commands SalaryClass = "", SalaryRef = "คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", - OcId = oc == null ? Guid.Empty : oc.Id, + OcId = lastSarary.OcId, - PositionLevel = placementProfile.PositionLevel, - PositionLineId = placementProfile.PositionLine!.Id, - PositionTypeId = placementProfile.PositionType!.Id, - OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, - PosNoId = positionNumber!.Id, + PositionLevel = lastSarary.PositionLevel, + PositionLineId = lastSarary.PositionLineId, + PositionTypeId = lastSarary.PositionTypeId, + OrganizationShortNameId = lastSarary.OrganizationShortNameId, + PosNoId = lastSarary.PosNoId, CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", CommandTypeName = command.CommandType.Name, @@ -3336,8 +3478,8 @@ namespace BMA.EHR.Application.Repositories.Commands PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id, - PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, - PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, + PositionExecutiveId = placementProfile.OrganizationPosition == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, + PositionExecutiveSideId = placementProfile.OrganizationPosition == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, IsActive = true, @@ -3372,7 +3514,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -3380,8 +3522,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -3400,7 +3542,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -3419,8 +3561,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -3447,6 +3589,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var data = await _dbContext.Set() @@ -3528,7 +3686,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -3536,8 +3694,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -3556,7 +3714,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -3575,8 +3733,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -3603,6 +3761,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var data = await _dbContext.Set() @@ -3686,7 +3860,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -3694,8 +3868,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -3714,7 +3888,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -3733,8 +3907,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -3761,6 +3935,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var data = await _dbContext.Set() @@ -3847,7 +4037,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -3855,8 +4045,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -3875,7 +4065,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -3894,8 +4084,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -3922,6 +4112,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var data = await _dbContext.Set() @@ -4010,7 +4216,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -4018,8 +4224,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -4038,7 +4244,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -4057,8 +4263,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -4085,6 +4291,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + // create new profile foreach (var recv in command.Receivers) { @@ -4339,7 +4561,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คุณได้รับโอนเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -4347,8 +4569,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คุณได้รับโอนเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -4369,7 +4591,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -4388,8 +4610,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -4416,6 +4638,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var data = await _dbContext.Set() @@ -4503,7 +4741,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -4511,8 +4749,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -4531,7 +4769,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งให้ช่วยราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -4550,8 +4788,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งให้ช่วยราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -4578,6 +4816,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var data = await _dbContext.Set() @@ -4665,7 +4919,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งส่งตัวกลับ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -4673,8 +4927,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งส่งตัวกลับ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -4693,7 +4947,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งส่งตัวกลับ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -4712,8 +4966,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งส่งตัวกลับ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -4740,6 +4994,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var data = await _dbContext.Set() @@ -4828,7 +5098,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -4836,8 +5106,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -4856,7 +5126,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -4875,8 +5145,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -4903,6 +5173,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var data = await _dbContext.Set() @@ -4991,7 +5277,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คุณได้รับคำสั่งให้ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -4999,8 +5285,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คุณได้รับคำสั่งให้ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -5019,7 +5305,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งให้ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -5038,8 +5324,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งให้ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -5066,6 +5352,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var data = await _dbContext.Set() @@ -5154,7 +5456,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -5162,8 +5464,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -5182,7 +5484,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -5201,8 +5503,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -5229,6 +5531,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var data = await _dbContext.Set() @@ -5317,7 +5635,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -5325,8 +5643,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -5345,7 +5663,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -5364,8 +5682,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -5392,6 +5710,22 @@ namespace BMA.EHR.Application.Repositories.Commands { try { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + foreach (var recv in command.Receivers) { var data = await _dbContext.Set() @@ -5408,42 +5742,42 @@ namespace BMA.EHR.Application.Repositories.Commands var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); var order = 1; - if (lastSarary.Order != null) + if (lastSarary != null && lastSarary.Order != null) order = lastSarary.Order.Value + 1; var salary = new ProfileSalary { Order = order, Date = command.CommandAffectDate, - Amount = lastSarary.Amount, - PositionSalaryAmount = lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary.MouthSalaryAmount, + Amount = recv.Amount, + PositionSalaryAmount = recv.PositionSalaryAmount, + MouthSalaryAmount = recv.MouthSalaryAmount, SalaryClass = "", SalaryRef = "คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", - OcId = lastSarary.OcId, + //OcId = lastSarary.OcId, - PositionLevel = lastSarary.PositionLevel, - PositionLineId = lastSarary.PositionLineId, - PositionTypeId = lastSarary.PositionTypeId, - OrganizationShortNameId = lastSarary.OrganizationShortNameId, - PosNoId = lastSarary.PosNoId, + //PositionLevel = lastSarary.PositionLevel, + //PositionLineId = lastSarary.PositionLineId, + //PositionTypeId = lastSarary.PositionTypeId, + //OrganizationShortNameId = lastSarary.OrganizationShortNameId, + //PosNoId = lastSarary.PosNoId, CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", CommandTypeName = command.CommandType.Name, - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - PosNoEmployee = "", + //PositionEmployeeGroupId = null, + //PositionEmployeeLevelId = null, + //PositionEmployeePositionId = null, + //PositionEmployeePositionSideId = null, + //PosNoEmployee = "", - //PositionPathSideId = lastSarary.PositionPathSideId == null, - PositionExecutiveId = lastSarary.PositionExecutiveId, - //PositionExecutiveSideId = lastSarary.PositionExecutiveSideId, + ////PositionPathSideId = lastSarary.PositionPathSideId == null, + //PositionExecutiveId = lastSarary.PositionExecutiveId, + ////PositionExecutiveSideId = lastSarary.PositionExecutiveSideId, IsActive = true, CreatedAt = DateTime.Now, @@ -5455,8 +5789,8 @@ namespace BMA.EHR.Application.Repositories.Commands }; - if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + //if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + //if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; data.Profile.Salaries.Add(salary); @@ -5477,7 +5811,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -5485,8 +5819,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คุณได้รับคำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = data.Profile.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); @@ -5505,7 +5839,7 @@ namespace BMA.EHR.Application.Repositories.Commands Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Payload = "", + Payload = payload_str, }; _dbContext.Set().Add(inbox); } @@ -5524,8 +5858,8 @@ namespace BMA.EHR.Application.Repositories.Commands { Body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = pf.Id, - Type = "", - Payload = "", + Type = "LINK", + Payload = payload_str, }; _dbContext.Set().Add(noti); } @@ -5555,6 +5889,7 @@ namespace BMA.EHR.Application.Repositories.Commands .Include(x => x.Placement) .Include(x => x.CommandType) .Include(x => x.Documents) + .ThenInclude(x => x.Document) .Include(x => x.Receivers) .Include(x => x.CommandStatus) .FirstOrDefaultAsync(x => x.Id == id); @@ -5604,6 +5939,8 @@ namespace BMA.EHR.Application.Repositories.Commands .Include(x => x.Receivers) .Include(x => x.Deployments) .Include(x => x.CommandType) + .Include(x => x.Documents) + .ThenInclude(x => x.Document) .FirstOrDefaultAsync(x => x.Id == id); if (command == null) diff --git a/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs b/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs index 917ea815..0c5ae691 100644 --- a/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs +++ b/BMA.EHR.Application/Repositories/MessageQueue/InboxRepository.cs @@ -1,9 +1,13 @@ using BMA.EHR.Application.Common.Interfaces; +using BMA.EHR.Application.Responses; +using BMA.EHR.Application.Responses.Messages; using BMA.EHR.Domain.Models.HR; using BMA.EHR.Domain.Models.Notifications; using BMA.EHR.Domain.Shared; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; +using System.Text.RegularExpressions; namespace BMA.EHR.Application.Repositories.MessageQueue { @@ -29,7 +33,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue #region " Methods " - public async Task> GetMyInboxAsync() + public async Task> GetMyInboxAsync() { try { @@ -44,6 +48,17 @@ namespace BMA.EHR.Application.Repositories.MessageQueue var data = await _dbContext.Set() .Where(x => x.ReceiverUserId == profile.Id) .OrderByDescending(x => x.ReceiveDate) + .Select(x => new InboxResponse + { + Subject = x.Subject, + Body = x.Body, + ReceiverUserId = x.ReceiverUserId, + IsOpen = x.IsOpen, + ReceiveDate = x.ReceiveDate, + OpenDate = x.OpenDate, + Payload = x.Payload == "" ? null : JsonConvert.DeserializeObject(Regex.Unescape(x.Payload)) + }) + .Take(20) .ToListAsync(); return data; diff --git a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs index 87023463..504d8517 100644 --- a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs +++ b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs @@ -1,9 +1,13 @@ using BMA.EHR.Application.Common.Interfaces; +using BMA.EHR.Application.Responses; +using BMA.EHR.Application.Responses.Messages; using BMA.EHR.Domain.Models.HR; using BMA.EHR.Domain.Models.Notifications; using BMA.EHR.Domain.Shared; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; +using System.Text.RegularExpressions; namespace BMA.EHR.Application.Repositories.MessageQueue { @@ -29,7 +33,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue #region " Methods " - public async Task> GetMyNotificationAsync() + public async Task> GetMyNotificationAsync() { try { @@ -44,6 +48,17 @@ namespace BMA.EHR.Application.Repositories.MessageQueue var data = await _dbContext.Set() .Where(x => x.ReceiverUserId == profile.Id) .OrderByDescending(x => x.ReceiveDate) + .Select(x => new NotificationResponse + { + Body = x.Body, + ReceiverUserId = x.ReceiverUserId, + IsOpen = x.IsOpen, + Type = x.Type, + ReceiveDate = x.ReceiveDate, + OpenDate = x.OpenDate, + Payload = x.Payload == "" ? null : JsonConvert.DeserializeObject(Regex.Unescape(x.Payload)) + }) + .Take(20) .ToListAsync(); return data; diff --git a/BMA.EHR.Application/Responses/CommandPayload.cs b/BMA.EHR.Application/Responses/CommandPayload.cs new file mode 100644 index 00000000..15e5598b --- /dev/null +++ b/BMA.EHR.Application/Responses/CommandPayload.cs @@ -0,0 +1,14 @@ +namespace BMA.EHR.Application.Responses +{ + public class CommandPayload + { + public List attachments { get; set; } + } + + public class PayloadAttachment + { + public string name { get; set; } + + public string url { get; set; } + } +} diff --git a/BMA.EHR.Application/Responses/Messages/InboxResponse.cs b/BMA.EHR.Application/Responses/Messages/InboxResponse.cs new file mode 100644 index 00000000..1652ff72 --- /dev/null +++ b/BMA.EHR.Application/Responses/Messages/InboxResponse.cs @@ -0,0 +1,19 @@ +namespace BMA.EHR.Application.Responses.Messages +{ + public class InboxResponse + { + public string Subject { get; set; } = string.Empty; + + public string Body { get; set; } = string.Empty; + + public Guid ReceiverUserId { get; set; } = Guid.Empty; + + public CommandPayload Payload { get; set; } = new CommandPayload(); + + public bool IsOpen { get; set; } = false; + + public DateTime ReceiveDate { get; set; } = DateTime.Now; + + public DateTime? OpenDate { get; set; } + } +} diff --git a/BMA.EHR.Application/Responses/Messages/NotificationResponse.cs b/BMA.EHR.Application/Responses/Messages/NotificationResponse.cs new file mode 100644 index 00000000..013b24cf --- /dev/null +++ b/BMA.EHR.Application/Responses/Messages/NotificationResponse.cs @@ -0,0 +1,19 @@ +namespace BMA.EHR.Application.Responses.Messages +{ + public class NotificationResponse + { + public string Body { get; set; } = string.Empty; + + public Guid ReceiverUserId { get; set; } = Guid.Empty; + + public string Type { get; set; } = "TEXT"; + + public CommandPayload Payload { get; set; } = new(); + + public bool IsOpen { get; set; } = false; + + public DateTime ReceiveDate { get; set; } = DateTime.Now; + + public DateTime? OpenDate { get; set; } + } +} diff --git a/BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj b/BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj index 96d01d2d..9e86639f 100644 --- a/BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj +++ b/BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj @@ -12,6 +12,7 @@ + diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 030c4f02..8466ef27 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -10,8 +10,11 @@ using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Commands.Core; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; +using iTextSharp.text; +using iTextSharp.text.pdf; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; using Swashbuckle.AspNetCore.Annotations; using System.Net.Http.Headers; using System.Security.Claims; @@ -38,6 +41,12 @@ namespace BMA.EHR.Command.Service.Controllers private readonly CommandStatusRepository _commandStatusRepository; private readonly UserProfileRepository _userProfileRepository; private readonly EmailSenderService _emailSenderService; + private readonly IWebHostEnvironment _hostingEnvironment; + private readonly MinIOService _minIOService; + private readonly IConfiguration _configuration; + + // for add watermark + private BaseFont baseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false); #endregion @@ -52,7 +61,10 @@ namespace BMA.EHR.Command.Service.Controllers CommandTypeRepository commandTypeRepository, CommandStatusRepository commandStatusRepository, UserProfileRepository userProfileRepository, - EmailSenderService emailSenderService) + EmailSenderService emailSenderService, + IWebHostEnvironment hostingEnvironment, + MinIOService minIOService, + IConfiguration configuration) { _repository = repository; _context = context; @@ -64,6 +76,9 @@ namespace BMA.EHR.Command.Service.Controllers _commandStatusRepository = commandStatusRepository; _userProfileRepository = userProfileRepository; _emailSenderService = emailSenderService; + _hostingEnvironment = hostingEnvironment; + _minIOService = minIOService; + _configuration = configuration; } #endregion @@ -91,21 +106,58 @@ namespace BMA.EHR.Command.Service.Controllers #region " Methods " - //[HttpGet("mail")] - //[AllowAnonymous] - //public IActionResult TestSendMail() - //{ - // try - // { - // _emailSenderService.SendMail("test send mail", "test body", "suphonchai@frappet.com"); + #region " Add Watermark " - // return Ok(); - // } - // catch - // { - // throw; - // } - //} + private void AddWaterMarkText(PdfContentByte pdfData, string watermarkText, BaseFont font, float fontSize, float angle, BaseColor color, Rectangle realPageSize) + { + var gstate = new PdfGState { FillOpacity = 0.5f, StrokeOpacity = 0.3f }; + pdfData.SaveState(); + pdfData.SetGState(gstate); + pdfData.SetColorFill(color); + pdfData.BeginText(); + pdfData.SetFontAndSize(font, fontSize); + var x = (realPageSize.Right + realPageSize.Left) / 2; + var y = (realPageSize.Bottom + realPageSize.Top) / 2; + pdfData.ShowTextAligned(Element.ALIGN_CENTER, watermarkText, x, y, angle); + pdfData.EndText(); + pdfData.RestoreState(); + } + + private bool AddWatermark(string inputfilepath, string outputfilepath, string watermark_text) + { + PdfReader pdfReader = null; + PdfStamper pdfStamper = null; + try + { + + pdfReader = new PdfReader(inputfilepath); + int numberOfPages = pdfReader.NumberOfPages; + iTextSharp.text.Rectangle pagesize = pdfReader.GetPageSize(1); + pdfStamper = new PdfStamper(pdfReader, new FileStream(outputfilepath, FileMode.Create)); + + for (int i = 1; i <= numberOfPages; i++) + { + var dc = pdfStamper.GetOverContent(i); + AddWaterMarkText(dc, watermark_text, baseFont, 30, 45, BaseColor.DARK_GRAY, pdfReader.GetPageSizeWithRotation(i)); + } + return true; + } + catch (Exception ex) + { + ex.Message.Trim(); + return false; + } + finally + { + if (pdfStamper != null) + pdfStamper.Close(); + + if (pdfReader != null) + pdfReader.Close(); + } + } + + #endregion /// /// แสดงปีเป็นปีพุทธศักราช โดยดึงจากข้อมูลที่มีในระบบ @@ -2602,7 +2654,7 @@ namespace BMA.EHR.Command.Service.Controllers try { var rawData = commandCode.Trim().ToUpper() == "C-PM-01" ? await _placementRepository.GetCompetitivePlacementAsync() : - commandCode.Trim().ToUpper() == "C-PM-02" ? await _placementRepository.GetQualifyingPlacementAsync() : + commandCode.Trim().ToUpper() == "C-PM-02" ? await _placementRepository.GetQualifyingPlacementAsync() : await _placementRepository.GetAllPlacementAsync(); @@ -3027,6 +3079,96 @@ namespace BMA.EHR.Command.Service.Controllers #region " Documents " + /// + /// Download เอกสารแนบ + /// + /// Record Id ของเอกสารแนบ + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("download/attachment/{docId}")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> DownloadAttachment(Guid docId) + { + var now = DateTime.Now.ToString("yyyyMMdd-HHmmss"); + var file = Path.Combine(_hostingEnvironment.ContentRootPath, "tmp", $"tmp-{now}.pdf"); + var file_copy = Path.Combine(_hostingEnvironment.ContentRootPath, "tmp", $"tmp-{now}-copy.pdf"); + + try + { + var doc = await _minIOService.DownloadFileAsync(docId); + + // Copy to File + System.IO.File.WriteAllBytes(file, doc.FileContent); + var watermark_text = "COPY COPY COPY COPY"; + var fName = Path.GetFileName(file); + + AddWatermark(file, file_copy, watermark_text); + + using (var fileStream = new System.IO.FileStream(file_copy, FileMode.Open, FileAccess.Read)) + { + using (var ms = new MemoryStream()) + { + fileStream.CopyTo(ms); + ms.Flush(); + return File(ms.ToArray(), "application/octet-stream", fName); + } + } + } + catch + { + throw; + } + finally + { + if (System.IO.File.Exists(file)) + System.IO.File.Delete(file); + + if (System.IO.File.Exists(file_copy)) + System.IO.File.Delete(file_copy); + } + } + + + [HttpGet("gen-payload/{orderId}")] + [AllowAnonymous] + public async Task> GetPayloadStr(Guid orderId) + { + try + { + var command = await _repository.GetByIdAsync(orderId); + if (command == null) + throw new Exception(GlobalMessages.CommandNotFound); + + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + + return Success(payload_str); + } + catch + { + throw; + } + } + + /// /// PM7-34 : ข้อมูลรายละเอียดคำสั่งและแนบท้าย /// diff --git a/BMA.EHR.Command.Service/appsettings.json b/BMA.EHR.Command.Service/appsettings.json index 468cc133..ab241292 100644 --- a/BMA.EHR.Command.Service/appsettings.json +++ b/BMA.EHR.Command.Service/appsettings.json @@ -41,5 +41,6 @@ "Password": "nnjazjcnwhepkxdm", "MailFrom": "suphonchai.ph@gmail.com", "Port": "587" - } + }, + "API": "https://bma-ehr.frappet.synology.me/api/v1" } \ No newline at end of file