From 1c939f6ffc63515b58bb942bffead0406b0b195e Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 9 Jan 2024 12:45:17 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=84=E0=B8=B3?= =?UTF-8?q?=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=A7=E0=B8=B4=E0=B8=99?= =?UTF-8?q?=E0=B8=B1=E0=B8=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/CommandRepository.cs | 534 ++++++++++++++++-- .../Controllers/OrderController.cs | 117 +++- .../Controllers/DisciplineResultController.cs | 8 +- .../DisciplineSuspendController.cs | 8 +- .../Controllers/CommandReportController.cs | 208 +++++-- 5 files changed, 784 insertions(+), 91 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 91c3e9ca..4348de11 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -2100,7 +2100,7 @@ namespace BMA.EHR.Application.Repositories.Commands var resultData = new List(); var baseAPI = _configuration["API"]; - var apiUrl = $"{baseAPI}/discipline/result/report/down"; + var apiUrl = $"{baseAPI}/discipline/result/report/up"; var commandType = await _dbContext.Set() .Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-30") @@ -2163,7 +2163,7 @@ namespace BMA.EHR.Application.Repositories.Commands var resultData = new List(); var baseAPI = _configuration["API"]; - var apiUrl = $"{baseAPI}/discipline/result/report/down"; + var apiUrl = $"{baseAPI}/discipline/result/report/up"; var commandType = await _dbContext.Set() .Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-31") @@ -6476,22 +6476,20 @@ namespace BMA.EHR.Application.Repositories.Commands foreach (var recv in command.Receivers) { - var data = await _dbContext.Set() - .Include(x => x.Profile) - .ThenInclude(x => x.Salaries) + var data = await _dbContext.Set() + .Include(x => x.Salaries) .ThenInclude(x => x.PositionLevel) - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); if (data == null) throw new Exception(GlobalMessages.DataNotFound); - data.Profile.IsActive = false; - data.Profile.IsLeave = true; - data.Profile.LeaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ"; - data.Profile.LeaveDate = command.CommandAffectDate; + data.IsActive = false; + data.IsLeave = true; + data.LeaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ"; + data.LeaveDate = command.CommandAffectDate; - var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); var order = 1; if (lastSarary.Order != null) order = lastSarary.Order.Value + 1; @@ -6545,19 +6543,16 @@ namespace BMA.EHR.Application.Repositories.Commands if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - data.Profile.Salaries.Add(salary); + data.Salaries.Add(salary); // remove profile position var profilePosition = await _dbContext.Set() .Include(x => x.Profile) .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == data.Profile.Id); + .FirstOrDefaultAsync(x => x.Profile!.Id == data.Id); if (profilePosition != null) _dbContext.Set().Remove(profilePosition); - // update placementstatus - data.Status = "DONE"; - await _dbContext.SaveChangesAsync(); // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ @@ -6571,7 +6566,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, + ReceiverUserId = data.Id, Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -6579,7 +6574,7 @@ namespace BMA.EHR.Application.Repositories.Commands var noti = new Notification { Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = data.Profile.Id, + ReceiverUserId = data.Id, Type = "LINK", Payload = payload_str, }; @@ -6681,9 +6676,8 @@ namespace BMA.EHR.Application.Repositories.Commands foreach (var recv in command.Receivers) { - var data = await _dbContext.Set() - .Include(x => x.Profile) - .ThenInclude(x => x.Salaries) + var data = await _dbContext.Set() + .Include(x => x.Salaries) .ThenInclude(x => x.PositionLevel) .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); @@ -6691,12 +6685,12 @@ namespace BMA.EHR.Application.Repositories.Commands if (data == null) throw new Exception(GlobalMessages.DataNotFound); - data.Profile.IsActive = false; - data.Profile.IsLeave = true; - data.Profile.LeaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ"; - data.Profile.LeaveDate = command.CommandAffectDate; + data.IsActive = false; + data.IsLeave = true; + data.LeaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ"; + data.LeaveDate = command.CommandAffectDate; - var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); var order = 1; if (lastSarary.Order != null) order = lastSarary.Order.Value + 1; @@ -6750,19 +6744,16 @@ namespace BMA.EHR.Application.Repositories.Commands if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - data.Profile.Salaries.Add(salary); + data.Salaries.Add(salary); // remove profile position var profilePosition = await _dbContext.Set() .Include(x => x.Profile) .Include(x => x.OrganizationPosition) - .FirstOrDefaultAsync(x => x.Profile!.Id == data.Profile.Id); + .FirstOrDefaultAsync(x => x.Profile!.Id == data.Id); if (profilePosition != null) _dbContext.Set().Remove(profilePosition); - // update placementstatus - data.Status = "DONE"; - await _dbContext.SaveChangesAsync(); // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ @@ -6776,7 +6767,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, + ReceiverUserId = data.Id, Payload = payload_str, }; _dbContext.Set().Add(inbox); @@ -6784,7 +6775,7 @@ namespace BMA.EHR.Application.Repositories.Commands var noti = new Notification { Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = data.Profile.Id, + ReceiverUserId = data.Id, Type = "LINK", Payload = payload_str, }; @@ -7643,6 +7634,65 @@ namespace BMA.EHR.Application.Repositories.Commands var res = await client.PostAsJsonAsync(apiUrl, new { result = data }); var result = await res.Content.ReadAsStringAsync(); } + // 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); + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + if (cc.IsSendInbox) + { + var inbox = new Inbox + { + 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_str, + }; + _dbContext.Set().Add(inbox); + } + + if (cc.IsSendMail) + { + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + } + + + var noti = new Notification + { + Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = pf.Id, + Type = "LINK", + Payload = payload_str, + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); } catch @@ -7675,6 +7725,65 @@ namespace BMA.EHR.Application.Repositories.Commands var res = await client.PostAsJsonAsync(apiUrl, new { result = data }); var result = await res.Content.ReadAsStringAsync(); } + // 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); + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + if (cc.IsSendInbox) + { + var inbox = new Inbox + { + 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_str, + }; + _dbContext.Set().Add(inbox); + } + + if (cc.IsSendMail) + { + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + } + + + var noti = new Notification + { + Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = pf.Id, + Type = "LINK", + Payload = payload_str, + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); } catch @@ -7707,6 +7816,65 @@ namespace BMA.EHR.Application.Repositories.Commands var res = await client.PostAsJsonAsync(apiUrl, new { result = data }); var result = await res.Content.ReadAsStringAsync(); } + // 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); + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + if (cc.IsSendInbox) + { + var inbox = new Inbox + { + 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_str, + }; + _dbContext.Set().Add(inbox); + } + + if (cc.IsSendMail) + { + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + } + + + var noti = new Notification + { + Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = pf.Id, + Type = "LINK", + Payload = payload_str, + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); } catch @@ -7739,6 +7907,65 @@ namespace BMA.EHR.Application.Repositories.Commands var res = await client.PostAsJsonAsync(apiUrl, new { result = data }); var result = await res.Content.ReadAsStringAsync(); } + // 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); + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + if (cc.IsSendInbox) + { + var inbox = new Inbox + { + 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_str, + }; + _dbContext.Set().Add(inbox); + } + + if (cc.IsSendMail) + { + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + } + + + var noti = new Notification + { + Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = pf.Id, + Type = "LINK", + Payload = payload_str, + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); } catch @@ -7771,6 +7998,65 @@ namespace BMA.EHR.Application.Repositories.Commands var res = await client.PostAsJsonAsync(apiUrl, new { result = data }); var result = await res.Content.ReadAsStringAsync(); } + // 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); + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + if (cc.IsSendInbox) + { + var inbox = new Inbox + { + 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_str, + }; + _dbContext.Set().Add(inbox); + } + + if (cc.IsSendMail) + { + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + } + + + var noti = new Notification + { + Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = pf.Id, + Type = "LINK", + Payload = payload_str, + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); } catch @@ -7795,7 +8081,7 @@ namespace BMA.EHR.Application.Repositories.Commands }); var baseAPI = _configuration["API"]; - var apiUrl = $"{baseAPI}/discipline/result/report/down/resume"; + var apiUrl = $"{baseAPI}/discipline/result/report/up/resume"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); @@ -7803,6 +8089,65 @@ namespace BMA.EHR.Application.Repositories.Commands var res = await client.PostAsJsonAsync(apiUrl, new { result = data }); var result = await res.Content.ReadAsStringAsync(); } + // 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); + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + if (cc.IsSendInbox) + { + var inbox = new Inbox + { + 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_str, + }; + _dbContext.Set().Add(inbox); + } + + if (cc.IsSendMail) + { + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + } + + + var noti = new Notification + { + Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = pf.Id, + Type = "LINK", + Payload = payload_str, + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); } catch @@ -7827,7 +8172,7 @@ namespace BMA.EHR.Application.Repositories.Commands }); var baseAPI = _configuration["API"]; - var apiUrl = $"{baseAPI}/discipline/result/report/down/resume"; + var apiUrl = $"{baseAPI}/discipline/result/report/up/resume"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); @@ -7835,6 +8180,65 @@ namespace BMA.EHR.Application.Repositories.Commands var res = await client.PostAsJsonAsync(apiUrl, new { result = data }); var result = await res.Content.ReadAsStringAsync(); } + // 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); + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + if (cc.IsSendInbox) + { + var inbox = new Inbox + { + 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_str, + }; + _dbContext.Set().Add(inbox); + } + + if (cc.IsSendMail) + { + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + } + + + var noti = new Notification + { + Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = pf.Id, + Type = "LINK", + Payload = payload_str, + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); } catch @@ -7867,6 +8271,65 @@ namespace BMA.EHR.Application.Repositories.Commands var res = await client.PostAsJsonAsync(apiUrl, new { result = data }); var result = await res.Content.ReadAsStringAsync(); } + // 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); + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + if (cc.IsSendInbox) + { + var inbox = new Inbox + { + 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_str, + }; + _dbContext.Set().Add(inbox); + } + + if (cc.IsSendMail) + { + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + } + + + var noti = new Notification + { + Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = pf.Id, + Type = "LINK", + Payload = payload_str, + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); } catch @@ -7917,6 +8380,7 @@ namespace BMA.EHR.Application.Repositories.Commands .Include(x => x.Placement) .Include(x => x.CommandType) .Include(x => x.CommandStatus) + .Include(x => x.Receivers) .OrderBy(x => x.CommandType.CommandCode) .ThenByDescending(x => x.CommandAffectDate) .ToListAsync(); diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 8571a908..e0df70e4 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -274,7 +274,29 @@ namespace BMA.EHR.Command.Service.Controllers //case "C-PM-17": case "C-PM-18": case "C-PM-19": + { + if (command.CommandNo != "" && + command.CommandYear != null && + command.CommandExcecuteDate != null && + cover != null) + { + return Success(new { result = "Y" }); + } + else + return Success(new { result = "N" }); + } case "C-PM-20": + { + if (command.CommandNo != "" && + command.CommandYear != null && + command.CommandExcecuteDate != null && + cover != null) + { + return Success(new { result = "Y" }); + } + else + return Success(new { result = "N" }); + } case "C-PM-21": case "C-PM-22": case "C-PM-23": @@ -291,13 +313,101 @@ namespace BMA.EHR.Command.Service.Controllers } case "C-PM-24": case "C-PM-25": + { + if (command.CommandNo != "" && + command.CommandYear != null && + command.CommandExcecuteDate != null && + cover != null) + { + return Success(new { result = "Y" }); + } + else + return Success(new { result = "N" }); + } case "C-PM-26": + { + if (command.CommandNo != "" && + command.CommandYear != null && + command.CommandExcecuteDate != null && + cover != null) + { + return Success(new { result = "Y" }); + } + else + return Success(new { result = "N" }); + } case "C-PM-27": + { + if (command.CommandNo != "" && + command.CommandYear != null && + command.CommandExcecuteDate != null && + cover != null) + { + return Success(new { result = "Y" }); + } + else + return Success(new { result = "N" }); + } case "C-PM-28": + { + if (command.CommandNo != "" && + command.CommandYear != null && + command.CommandExcecuteDate != null && + cover != null) + { + return Success(new { result = "Y" }); + } + else + return Success(new { result = "N" }); + } case "C-PM-29": + { + if (command.CommandNo != "" && + command.CommandYear != null && + command.CommandExcecuteDate != null && + cover != null) + { + return Success(new { result = "Y" }); + } + else + return Success(new { result = "N" }); + } case "C-PM-30": + { + if (command.CommandNo != "" && + command.CommandYear != null && + command.CommandExcecuteDate != null && + cover != null) + { + return Success(new { result = "Y" }); + } + else + return Success(new { result = "N" }); + } case "C-PM-31": + { + if (command.CommandNo != "" && + command.CommandYear != null && + command.CommandExcecuteDate != null && + cover != null) + { + return Success(new { result = "Y" }); + } + else + return Success(new { result = "N" }); + } case "C-PM-32": + { + if (command.CommandNo != "" && + command.CommandYear != null && + command.CommandExcecuteDate != null && + cover != null) + { + return Success(new { result = "Y" }); + } + else + return Success(new { result = "N" }); + } default: { if (command.CommandNo != "" && @@ -406,7 +516,12 @@ namespace BMA.EHR.Command.Service.Controllers OrderStatusValue = d.CommandStatusId, OrderStatusName = d.CommandStatus.Name, OrderTypeValue = d.CommandTypeId, - OrderTypeName = d.CommandType.Name + OrderTypeName = d.CommandType.Name, + FaultLevel = d.FaultLevel, + CaseFault = d.CaseFault, + Result = d.Result, + RefRaw = d.RefRaw, + FullName = d.Receivers.FirstOrDefault() == null ? null : $"{d.Receivers.FirstOrDefault().Prefix!}{d.Receivers.FirstOrDefault().FirstName!} {d.Receivers.FirstOrDefault().LastName!}", }).ToList(); return Success(data); } diff --git a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs index f09a1677..2ee4e7a4 100644 --- a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs +++ b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs @@ -426,7 +426,10 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => x.Id == d.id) .FirstOrDefaultAsync(); if (data != null) + { data.Status = "NEW"; + data.CommandTypeId = null; + } await _context.SaveChangesAsync(); } return Success(); @@ -450,7 +453,10 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => x.Id == d.id) .FirstOrDefaultAsync(); if (data != null) + { data.StatusDiscard = "NEW"; + data.CommandTypeDiscardId = null; + } await _context.SaveChangesAsync(); } return Success(); @@ -504,7 +510,7 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => x.Id == d.id) .FirstOrDefaultAsync(); if (data != null) - data.Status = "NEW"; + data.Status = "DONE"; await _context.SaveChangesAsync(); } return Success(); diff --git a/BMA.EHR.Discipline.Service/Controllers/DisciplineSuspendController.cs b/BMA.EHR.Discipline.Service/Controllers/DisciplineSuspendController.cs index cd7d3189..b64636ca 100644 --- a/BMA.EHR.Discipline.Service/Controllers/DisciplineSuspendController.cs +++ b/BMA.EHR.Discipline.Service/Controllers/DisciplineSuspendController.cs @@ -175,9 +175,9 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน - [HttpPost("report")] - // [HttpPut("report/{commandTypeId:length(36)}")] - public async Task> PostToReport([FromBody] DisciplineProfileRequest req) + // [HttpPost("report")] + [HttpPut("report/{commandTypeId:length(36)}")] + public async Task> PostToReport([FromBody] DisciplineProfileRequest req, Guid commandTypeId) { foreach (var item in req.Id) { @@ -186,7 +186,7 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers if (uppdated == null) continue; - // uppdated.CommandTypeId = commandTypeId; + uppdated.CommandTypeId = commandTypeId; uppdated.Status = "REPORT"; uppdated.LastUpdateFullName = FullName ?? "System Administrator"; uppdated.LastUpdateUserId = UserId ?? ""; diff --git a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs index 89146f0d..5cd07787 100644 --- a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs @@ -1905,42 +1905,80 @@ namespace BMA.EHR.Report.Service.Controllers #region " C-PM-19 " - private async Task GenerateCommandReportType19_Cover(Guid commandId, string exportType) + private async Task GenerateCommandReportType19_Cover(Guid commandId, string exportType) { try { - var command = await _repository.GetByIdAsync(commandId); - if (command == null) + // var command = await _repository.GetByIdAsync(commandId); + // if (command == null) + // { + // throw new Exception(GlobalMessages.CommandNotFound); + // } + + // var data = await _commandReportRepository.GetCommandType19Async(commandId); + + // var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"37-คำสั่งปลดออกจากราชการ.trdp"); + + // ReportPackager reportPackager = new ReportPackager(); + // Telerik.Reporting.Report? report = null; + // using (var sourceStream = System.IO.File.OpenRead(rptFile)) + // { + // report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); + // } + + // report.DataSource = data; + + // System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + + // InstanceReportSource instanceReportSource = new InstanceReportSource() + // { + // ReportDocument = report + // }; + + // ReportProcessor reportProcessor = new ReportProcessor(_configuration); + // RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo); + + // var content = result.DocumentBytes; + + // return content; + var raw_data = await _repository.GetByIdAsync(commandId); + if (raw_data == null) { throw new Exception(GlobalMessages.CommandNotFound); } - var data = await _commandReportRepository.GetCommandType19Async(commandId); + var raw_data_profile = await _commandReportRepository.GetCommandType25AttachmentAsync(commandId); - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"37-คำสั่งปลดออกจากราชการ.trdp"); - - ReportPackager reportPackager = new ReportPackager(); - Telerik.Reporting.Report? report = null; - using (var sourceStream = System.IO.File.OpenRead(rptFile)) + var command = new { - report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); - } + No = raw_data.CommandNo.ToThaiNumber(), + Year = raw_data.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(), + Issuerorganizationname = raw_data.IssuerOrganizationName, + ConclusionRegisterNo = raw_data.ConclusionRegisterNo.ToThaiNumber(), + ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3().ToThaiNumber(), + ConclusionResultNo = raw_data.ConclusionResultNo.ToThaiNumber(), + ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3().ToThaiNumber(), + PositionList = "", + Count = raw_data.Receivers.Count.ToString().ToThaiNumber(), + CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3().ToThaiNumber(), + AuthorizedUserFullName = raw_data.AuthorizedUserFullName, + AuthorizedPosition = raw_data.AuthorizedPosition, + ReceiveOrganizationName = raw_data.ReceiveOrganizationName, + Title = $"{raw_data.CommandSubject}", - report.DataSource = data; + CaseFault = raw_data.CaseFault, + FaultLevel = raw_data.FaultLevel, + RefRaw = raw_data.RefRaw, + Result = raw_data.Result, - System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - - InstanceReportSource instanceReportSource = new InstanceReportSource() - { - ReportDocument = report + Fullname = raw_data_profile == null ? "" : raw_data_profile.FullName, + Positionname = raw_data_profile == null ? "" : raw_data_profile.Positionname, + Positionno = raw_data_profile == null ? "" : raw_data_profile.Positionno, + Organizationname = raw_data_profile == null ? "" : raw_data_profile.Organizationname, + Salary = raw_data_profile == null ? "" : raw_data_profile.Salary, }; - ReportProcessor reportProcessor = new ReportProcessor(_configuration); - RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo); - - var content = result.DocumentBytes; - - return content; + return command; } catch { @@ -1952,42 +1990,80 @@ namespace BMA.EHR.Report.Service.Controllers #region " C-PM-20 " - private async Task GenerateCommandReportType20_Cover(Guid commandId, string exportType) + private async Task GenerateCommandReportType20_Cover(Guid commandId, string exportType) { try { - var command = await _repository.GetByIdAsync(commandId); - if (command == null) + // var command = await _repository.GetByIdAsync(commandId); + // if (command == null) + // { + // throw new Exception(GlobalMessages.CommandNotFound); + // } + + // var data = await _commandReportRepository.GetCommandType20Async(commandId); + + // var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"38-คำสั่งลงโทษไล่ข้าราชการออกจากราชการ.trdp"); + + // ReportPackager reportPackager = new ReportPackager(); + // Telerik.Reporting.Report? report = null; + // using (var sourceStream = System.IO.File.OpenRead(rptFile)) + // { + // report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); + // } + + // report.DataSource = data; + + // System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + + // InstanceReportSource instanceReportSource = new InstanceReportSource() + // { + // ReportDocument = report + // }; + + // ReportProcessor reportProcessor = new ReportProcessor(_configuration); + // RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo); + + // var content = result.DocumentBytes; + + // return content; + var raw_data = await _repository.GetByIdAsync(commandId); + if (raw_data == null) { throw new Exception(GlobalMessages.CommandNotFound); } - var data = await _commandReportRepository.GetCommandType20Async(commandId); + var raw_data_profile = await _commandReportRepository.GetCommandType25AttachmentAsync(commandId); - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"38-คำสั่งลงโทษไล่ข้าราชการออกจากราชการ.trdp"); - - ReportPackager reportPackager = new ReportPackager(); - Telerik.Reporting.Report? report = null; - using (var sourceStream = System.IO.File.OpenRead(rptFile)) + var command = new { - report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); - } + No = raw_data.CommandNo.ToThaiNumber(), + Year = raw_data.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(), + Issuerorganizationname = raw_data.IssuerOrganizationName, + ConclusionRegisterNo = raw_data.ConclusionRegisterNo.ToThaiNumber(), + ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3().ToThaiNumber(), + ConclusionResultNo = raw_data.ConclusionResultNo.ToThaiNumber(), + ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3().ToThaiNumber(), + PositionList = "", + Count = raw_data.Receivers.Count.ToString().ToThaiNumber(), + CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3().ToThaiNumber(), + AuthorizedUserFullName = raw_data.AuthorizedUserFullName, + AuthorizedPosition = raw_data.AuthorizedPosition, + ReceiveOrganizationName = raw_data.ReceiveOrganizationName, + Title = $"{raw_data.CommandSubject}", - report.DataSource = data; + CaseFault = raw_data.CaseFault, + FaultLevel = raw_data.FaultLevel, + RefRaw = raw_data.RefRaw, + Result = raw_data.Result, - System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - - InstanceReportSource instanceReportSource = new InstanceReportSource() - { - ReportDocument = report + Fullname = raw_data_profile == null ? "" : raw_data_profile.FullName, + Positionname = raw_data_profile == null ? "" : raw_data_profile.Positionname, + Positionno = raw_data_profile == null ? "" : raw_data_profile.Positionno, + Organizationname = raw_data_profile == null ? "" : raw_data_profile.Organizationname, + Salary = raw_data_profile == null ? "" : raw_data_profile.Salary, }; - ReportProcessor reportProcessor = new ReportProcessor(_configuration); - RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo); - - var content = result.DocumentBytes; - - return content; + return command; } catch { @@ -3756,7 +3832,6 @@ namespace BMA.EHR.Report.Service.Controllers { case "pdf": mimeType = "application/pdf"; break; case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; - case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } var cmd = await _repository.GetByIdAsync(id); @@ -3764,7 +3839,24 @@ namespace BMA.EHR.Report.Service.Controllers throw new Exception(GlobalMessages.CommandNotFound); var contentData = await GenerateCommandReportType19_Cover(id, exportType); - return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); + var data = new + { + template = "DP6_005", + reportName = "docx-report", + data = contentData + }; + // var apiUrl = "https://report-server.frappet.synology.me/api/v1/report-template/docx"; + // using (var client = new HttpClient()) + // { + // // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); + // var req = new HttpRequestMessage(HttpMethod.Post, apiUrl); + // // var res = await client.SendAsync(req); + // var res = await client.PostAsJsonAsync(apiUrl, data); + // var result = await res.Content.ReadAsStringAsync(); + // return Success(res); + + // } + return Success(data); } catch { @@ -3799,7 +3891,6 @@ namespace BMA.EHR.Report.Service.Controllers { case "pdf": mimeType = "application/pdf"; break; case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; - case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } var cmd = await _repository.GetByIdAsync(id); @@ -3807,7 +3898,24 @@ namespace BMA.EHR.Report.Service.Controllers throw new Exception(GlobalMessages.CommandNotFound); var contentData = await GenerateCommandReportType20_Cover(id, exportType); - return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); + var data = new + { + template = "DP6_008", + reportName = "docx-report", + data = contentData + }; + // var apiUrl = "https://report-server.frappet.synology.me/api/v1/report-template/docx"; + // using (var client = new HttpClient()) + // { + // // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); + // var req = new HttpRequestMessage(HttpMethod.Post, apiUrl); + // // var res = await client.SendAsync(req); + // var res = await client.PostAsJsonAsync(apiUrl, data); + // var result = await res.Content.ReadAsStringAsync(); + // return Success(res); + + // } + return Success(data); } catch {