diff --git a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs index 717069ce..633dcf2e 100644 --- a/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs +++ b/BMA.EHR.Application/Repositories/MessageQueue/NotificationRepository.cs @@ -233,6 +233,54 @@ namespace BMA.EHR.Application.Repositories.MessageQueue throw; } } + + public async Task PushNotificationsAsync(Guid[] ReceiverUserIds, string Subject, string Body, string Payload = "", bool IsSendInbox = false, bool IsSendMail = false) + { + try + { + foreach (var ReceiverUserId in ReceiverUserIds) + { + _dbContext.Set().Add(new Notification + { + Body = Body, + ReceiverUserId = ReceiverUserId, + Type = "", + Payload = Payload, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + CreatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + }); + if (IsSendInbox == true) + { + _dbContext.Set().Add(new Inbox + { + Subject = Subject, + Body = Body, + ReceiverUserId = ReceiverUserId, + Payload = Payload, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + CreatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + }); + } + if (IsSendMail == true) + { + _emailSenderService.SendMail(Subject, Body, "kittapath@frappet.com"); + } + } + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } public async Task PushNotificationAsyncV2(string? ReceiverUserId, string Subject, string Body, string Payload = "", bool IsSendInbox = false, bool IsSendMail = false) { try diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 613e52f1..16867ddf 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -3,10 +3,10 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.Commands; using BMA.EHR.Application.Requests.Commands; using BMA.EHR.Application.Responses; +using BMA.EHR.Domain.Extensions; using BMA.EHR.Command.Service.Requests; using BMA.EHR.Command.Service.Responses; using BMA.EHR.Domain.Common; -using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Commands.Core; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -16,11 +16,11 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Swashbuckle.AspNetCore.Annotations; -using System.Net; using System.Net.Http.Headers; using System.Security.Claims; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Microsoft.EntityFrameworkCore; +using BMA.EHR.Application.Responses.Reports; namespace BMA.EHR.Command.Service.Controllers { diff --git a/BMA.EHR.Command.Service/Requests/ReportAttachmentRequest.cs b/BMA.EHR.Command.Service/Requests/ReportAttachmentRequest.cs new file mode 100644 index 00000000..a3ddafe6 --- /dev/null +++ b/BMA.EHR.Command.Service/Requests/ReportAttachmentRequest.cs @@ -0,0 +1,26 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Command.Service.Requests +{ + public class ReportAttachmentRequest + { + public ReportAttachmentRequestObj[] refIds { get; set; } + } + public class ReportAttachmentRequestObj + { + public string? refId { get; set; } + public int? Sequence { get; set; } + public string? CitizenId { get; set; } + public string? Prefix { get; set; } + public string? FirstName { get; set; } + public string? LastName { get; set; } + public double? Amount { get; set; } + public double? PositionSalaryAmount { get; set; } + public double? MouthSalaryAmount { get; set; } + public string? RemarkHorizontal { get; set; } + public string? RemarkVertical { get; set; } + public int CommandYear { get; set; } + + } +} diff --git a/BMA.EHR.Command.Service/Requests/ReportExecuteRequest.cs b/BMA.EHR.Command.Service/Requests/ReportExecuteRequest.cs new file mode 100644 index 00000000..c66de13b --- /dev/null +++ b/BMA.EHR.Command.Service/Requests/ReportExecuteRequest.cs @@ -0,0 +1,21 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Command.Service.Requests +{ + public class ReportExecuteRequest + { + public ReportExecuteRequestObj[] refIds { get; set; } + } + public class ReportExecuteRequestObj + { + public string? refId { get; set; } + public DateTime commandAffectDate { get; set; } + public string? commandNo { get; set; } + public int commandYear { get; set; } + public string? templateDoc { get; set; } + public double? amount { get; set; } + public double? positionSalaryAmount { get; set; } + public double? mouthSalaryAmount { get; set; } + } +} diff --git a/BMA.EHR.Command.Service/Requests/ReportPersonRequest.cs b/BMA.EHR.Command.Service/Requests/ReportPersonRequest.cs new file mode 100644 index 00000000..3747c878 --- /dev/null +++ b/BMA.EHR.Command.Service/Requests/ReportPersonRequest.cs @@ -0,0 +1,10 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Command.Service.Requests +{ + public class ReportPersonRequest + { + public string[] refIds { get; set; } + } +} diff --git a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs index 6e90ce13..ea26afc1 100644 --- a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs +++ b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs @@ -1,6 +1,7 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Discipline.Service.Requests; +using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Models.Commands.Core; using BMA.EHR.Domain.Models.Discipline; @@ -517,7 +518,7 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlDiscipline); var _res = await client.PostAsJsonAsync(apiUrlDiscipline, new { - profileId = d.personId, + profileId = data.PersonId, date = d.commandAffectDate, detail = data.DisciplineDisciplinary.Title, level = data.DisciplineDisciplinary.DisciplinaryFaultLevel, @@ -564,7 +565,7 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlDiscipline); var _res = await client.PostAsJsonAsync(apiUrlDiscipline, new { - profileId = d.personId, + profileId = data.PersonId, date = d.commandAffectDate, detail = data.DisciplineDisciplinary.Title, level = data.DisciplineDisciplinary.DisciplinaryFaultLevel, @@ -610,7 +611,7 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlDiscipline); var _res = await client.PostAsJsonAsync(apiUrlDiscipline, new { - profileId = d.personId, + profileId = data1.PersonId, date = d.commandAffectDate, detail = data1.DisciplineInvestigate.Title, level = "", @@ -638,7 +639,7 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlDiscipline); var _res = await client.PostAsJsonAsync(apiUrlDiscipline, new { - profileId = d.personId, + profileId = data2.PersonId, date = d.commandAffectDate, detail = data2.DisciplineDisciplinary.Title, level = data2.DisciplineDisciplinary.DisciplinaryFaultLevel, @@ -684,7 +685,7 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlDiscipline); var _res = await client.PostAsJsonAsync(apiUrlDiscipline, new { - profileId = d.personId, + profileId = data.PersonId, date = d.commandAffectDate, detail = data.DisciplineDisciplinary.Title, level = data.DisciplineDisciplinary.DisciplinaryFaultLevel, @@ -708,30 +709,26 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน - [HttpGet("report/find/{periodId:guid}/{personId:guid}")] - public async Task> GetPersonReportFind(Guid periodId, Guid personId) + [HttpGet("report/find/{periodId:guid}")] + public async Task> GetPersonReportFind(Guid periodId) { var data1 = await _context.DisciplineComplaint_Profiles .Where(x => x.Id == periodId) - .Where(x => x.PersonId == personId.ToString()) .FirstOrDefaultAsync(); if (data1 == null) { var data2 = await _context.DisciplineInvestigate_ProfileComplaints .Where(x => x.Id == periodId) - .Where(x => x.PersonId == personId.ToString()) .FirstOrDefaultAsync(); if (data2 == null) { var data3 = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates .Where(x => x.Id == periodId) - .Where(x => x.PersonId == personId.ToString()) .FirstOrDefaultAsync(); if (data3 == null) { var data4 = await _context.DisciplineReport_Profiles .Where(x => x.Id == periodId) - .Where(x => x.PersonId == personId.ToString()) .FirstOrDefaultAsync(); return Success(data4); } @@ -742,5 +739,1143 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers return Success(data1); } + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-19 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command19/report")] + public async Task> PostReportCommand19([FromBody] ReportPersonRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-19 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command19/report/delete")] + public async Task> PostReportDeleteCommand19([FromBody] ReportPersonRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + data.ForEach(profile => profile.Status = "NEW"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ออกคำสั่ง C-PM-19 คำสั่งปลดออกจากราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command19/report/excecute")] + public async Task> PostReportCommand19Execute([FromBody] ReportExecuteRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = true, + leaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ", + dateLeave = r.commandAffectDate, + refCommandDate = DateTime.Now, + detail = p.DisciplineDisciplinary.Title, + level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, + unStigma = "คำสั่งลงโทษ ปลดออกจากราชการ", + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-20 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command20/report")] + public async Task> PostReportcommand20([FromBody] ReportPersonRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-20 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command20/report/delete")] + public async Task> PostReportDeletecommand20([FromBody] ReportPersonRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + data.ForEach(profile => profile.Status = "NEW"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ออกคำสั่ง C-PM-20 คำสั่งไล่ออกจากราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command20/report/excecute")] + public async Task> PostReportCommand20Execute([FromBody] ReportExecuteRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = true, + leaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ", + dateLeave = r.commandAffectDate, + refCommandDate = DateTime.Now, + detail = p.DisciplineDisciplinary.Title, + level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, + unStigma = "คำสั่งลงโทษ ไล่ออกจากราชการ", + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-25 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command25/report")] + public async Task> PostReportCommand25([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineReport_Profiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-25 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command25/report/delete")] + public async Task> PostReportDeleteCommand25([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineReport_Profiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + data.ForEach(profile => profile.Status = "PENDING"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// เอกสารแนบท้าย C-PM-25 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command25/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportCommand25Attachment([FromBody] ReportAttachmentRequest req) + { + try + { + var data = await _context.DisciplineReport_Profiles + // .Where(x => x.Status == "REPORT") + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + fullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + positionname = p.Position, + positionno = p.PosNo, + organizationname = p.Organization, + salary = r.Amount + }).ToList(); + + return Success(resultData); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-25 คำสั่งพักจากราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command25/report/excecute")] + public async Task> PostReportCommand25Execute([FromBody] ReportExecuteRequest req) + { + var data = await _context.DisciplineReport_Profiles + .Include(x => x.DisciplineDisciplinary) + // .Where(x => x.Status == "REPORT") + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = true, + leaveReason = "ได้รับโทษทางวินัย พักจากราชการ", + dateLeave = r.commandAffectDate, + refCommandDate = DateTime.Now, + detail = p.DisciplineDisciplinary.Title, + level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, + unStigma = "คำสั่งลงโทษ พักจากราชการ", + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-26 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command26/report")] + public async Task> PostReportCommand26([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineReport_Profiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-26 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command26/report/delete")] + public async Task> PostReportDeleteCommand26([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineReport_Profiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + data.ForEach(profile => profile.Status = "PENDING"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-26 คำสั่งให้ออกจากราชการไว้ก่อน + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command26/report/excecute")] + public async Task> PostReportCommand26Execute([FromBody] ReportExecuteRequest req) + { + + var data = await _context.DisciplineReport_Profiles + .Include(x => x.DisciplineDisciplinary) + // .Where(x => x.Status == "REPORT") + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = true, + leaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน", + dateLeave = r.commandAffectDate, + refCommandDate = DateTime.Now, + detail = p.DisciplineDisciplinary.Title, + level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, + unStigma = "คำสั่งลงโทษ ให้ออกจากราชการไว้ก่อน", + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-27 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command27/report")] + public async Task> PostReportCommand27([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-27 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command27/report/delete")] + public async Task> PostReportDeleteCommand27([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + data.ForEach(profile => profile.Status = "NEW"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-27 คำสั่งลงโทษ ภาคทัณฑ์ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command27/report/excecute")] + public async Task> PostReportCommand27Execute([FromBody] ReportExecuteRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + string? _null = null; + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = _null, + leaveReason = _null, + dateLeave = _null, + refCommandDate = DateTime.Now, + detail = p.DisciplineDisciplinary.Title, + level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, + unStigma = "คำสั่งลงโทษ ลงโทษ ภาคทัณฑ์", + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-28 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command28/report")] + public async Task> PostReportCommand28([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-28 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command28/report/delete")] + public async Task> PostReportDeleteCommand28([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + data.ForEach(profile => profile.Status = "NEW"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-28 คำสั่งลงโทษ ตัดเงินเดือน + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command28/report/excecute")] + public async Task> PostReportCommand28Execute([FromBody] ReportExecuteRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + string? _null = null; + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = _null, + leaveReason = _null, + dateLeave = _null, + refCommandDate = DateTime.Now, + detail = p.DisciplineDisciplinary.Title, + level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, + unStigma = "คำสั่งลงโทษ ตัดเงินเดือน" + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-29 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command29/report")] + public async Task> PostReportCommand29([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-29 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command29/report/delete")] + public async Task> PostReportDeleteCommand29([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + data.ForEach(profile => profile.Status = "NEW"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-29 คำสั่งลงโทษ ลดขั้นเงินเดือน + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command29/report/excecute")] + public async Task> PostReportCommand29Execute([FromBody] ReportExecuteRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + string? _null = null; + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = _null, + leaveReason = _null, + dateLeave = _null, + refCommandDate = DateTime.Now, + detail = p.DisciplineDisciplinary.Title, + level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, + unStigma = "คำสั่งลงโทษ ลดขั้นเงินเดือน" + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-30 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command30/report")] + public async Task> PostReportCommand30([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-30 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command30/report/delete")] + public async Task> PostReportDeleteCommand30([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + data.ForEach(profile => profile.Status = "NEW"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-30 คำสั่งเพิ่มโทษ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command30/report/excecute")] + public async Task> PostReportCommand30Execute([FromBody] ReportExecuteRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + string? _null = null; + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = _null, + leaveReason = _null, + dateLeave = _null, + refCommandDate = DateTime.Now, + detail = p.DisciplineDisciplinary.Title, + level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, + unStigma = "คำสั่งเพิ่มโทษ" + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-31 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command31/report")] + public async Task> PostReportCommand31([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-31 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command31/report/delete")] + public async Task> PostReportDeleteCommand31([FromBody] ReportPersonRequest req) + { + try + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + data.ForEach(profile => profile.Status = "NEW"); + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-31 คำสั่งงดโทษ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command31/report/excecute")] + public async Task> PostReportCommand31Execute([FromBody] ReportExecuteRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + string? _null = null; + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = _null, + leaveReason = _null, + dateLeave = _null, + refCommandDate = DateTime.Now, + detail = p.DisciplineDisciplinary.Title, + level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, + unStigma = "คำสั่งงดโทษ" + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-32 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command32/report")] + public async Task> PostReportCommand32([FromBody] ReportPersonRequest req) + { + try + { + var data1 = await _context.DisciplineInvestigate_ProfileComplaints + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + + data1.ForEach(profile => profile.IsReport = "REPORT"); + var data2 = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + + data2.ForEach(profile => profile.IsReport = "REPORT"); + + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-32 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command32/report/delete")] + public async Task> PostReportDeleteCommand32([FromBody] ReportPersonRequest req) + { + try + { + var data1 = await _context.DisciplineInvestigate_ProfileComplaints + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.IsReport == "REPORT") + .ToListAsync(); + + data1.ForEach(profile => profile.IsReport = "NEW"); + var data2 = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.IsReport == "REPORT") + .ToListAsync(); + + data2.ForEach(profile => profile.IsReport = "NEW"); + + await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-32 คำสั่งยุติเรื่อง + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command32/report/excecute")] + public async Task> PostReportCommand32Execute([FromBody] ReportExecuteRequest req) + { + var data = await _context.DisciplineInvestigate_ProfileComplaints + .Include(x => x.DisciplineInvestigate) + // .Where(x => x.IsReport == "REPORT") + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + string? _null = null; + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = false, + leaveReason = _null, + dateLeave = _null, + refCommandDate = DateTime.Now, + detail = p.DisciplineInvestigate.Title, + level = "", + unStigma = "คำสั่งยุติเรื่อง" + }).ToList(); + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.IsReport = "DONE"); + await _context.SaveChangesAsync(); + } + } + + var data1 = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + // .Where(x => x.IsReport == "REPORT") + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData1 = (from p in data1 + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = false, + leaveReason = _null, + dateLeave = _null, + refCommandDate = DateTime.Now, + detail = p.DisciplineDisciplinary.Title, + level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, + unStigma = "คำสั่งยุติเรื่อง" + }).ToList(); + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData1, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data1.ForEach(profile => profile.IsReport = "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 13d77be1..ca57e9cd 100644 --- a/BMA.EHR.Discipline.Service/Controllers/DisciplineSuspendController.cs +++ b/BMA.EHR.Discipline.Service/Controllers/DisciplineSuspendController.cs @@ -86,7 +86,7 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers Prefix = x.Prefix, FirstName = x.FirstName, LastName = x.LastName, - + ProfileId = x.PersonId, Organization = x.Organization, root = x.root, rootId = x.rootId, diff --git a/BMA.EHR.Discipline.Service/Requests/PassDisciplineResponse.cs b/BMA.EHR.Discipline.Service/Requests/PassDisciplineResponse.cs index c95f888c..2e3a8a81 100644 --- a/BMA.EHR.Discipline.Service/Requests/PassDisciplineResponse.cs +++ b/BMA.EHR.Discipline.Service/Requests/PassDisciplineResponse.cs @@ -11,7 +11,7 @@ namespace BMA.EHR.Discipline.Service.Requests public class DisciplineDataResponse { public Guid id { get; set; } = Guid.Empty; - public Guid personId { get; set; } = Guid.Empty; + // public Guid personId { get; set; } = Guid.Empty; public Guid? commandId { get; set; } = Guid.Empty; public DateTime? commandAffectDate { get; set; } diff --git a/BMA.EHR.Discipline.Service/Requests/ReportAttachmentRequest.cs b/BMA.EHR.Discipline.Service/Requests/ReportAttachmentRequest.cs new file mode 100644 index 00000000..e371d927 --- /dev/null +++ b/BMA.EHR.Discipline.Service/Requests/ReportAttachmentRequest.cs @@ -0,0 +1,25 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Discipline.Service.Requests +{ + public class ReportAttachmentRequest + { + public ReportAttachmentRequestObj[] refIds { get; set; } + } + public class ReportAttachmentRequestObj + { + public string? refId { get; set; } + public int? Sequence { get; set; } + public string? CitizenId { get; set; } + public string? Prefix { get; set; } + public string? FirstName { get; set; } + public string? LastName { get; set; } + public double? Amount { get; set; } + public double? PositionSalaryAmount { get; set; } + public double? MouthSalaryAmount { get; set; } + public string? RemarkHorizontal { get; set; } + public string? RemarkVertical { get; set; } + public int CommandYear { get; set; } + } +} diff --git a/BMA.EHR.Discipline.Service/Requests/ReportExecuteRequest.cs b/BMA.EHR.Discipline.Service/Requests/ReportExecuteRequest.cs new file mode 100644 index 00000000..c7446828 --- /dev/null +++ b/BMA.EHR.Discipline.Service/Requests/ReportExecuteRequest.cs @@ -0,0 +1,21 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Discipline.Service.Requests +{ + public class ReportExecuteRequest + { + public ReportExecuteRequestObj[] refIds { get; set; } + } + public class ReportExecuteRequestObj + { + public string? refId { get; set; } + public DateTime commandAffectDate { get; set; } + public string? commandNo { get; set; } + public int commandYear { get; set; } + public string? templateDoc { get; set; } + public double? amount { get; set; } + public double? positionSalaryAmount { get; set; } + public double? mouthSalaryAmount { get; set; } + } +} diff --git a/BMA.EHR.Discipline.Service/Requests/ReportPersonRequest.cs b/BMA.EHR.Discipline.Service/Requests/ReportPersonRequest.cs new file mode 100644 index 00000000..f393a864 --- /dev/null +++ b/BMA.EHR.Discipline.Service/Requests/ReportPersonRequest.cs @@ -0,0 +1,10 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Discipline.Service.Requests +{ + public class ReportPersonRequest + { + public string[] refIds { get; set; } + } +} diff --git a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs index 15d8c383..e7f8fc7b 100644 --- a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs +++ b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs @@ -2028,7 +2028,7 @@ namespace BMA.EHR.Insignia.Service.Controllers [HttpPut("note/doc/{insigniaNoteId:length(36)}")] public async Task> AddDocumentProfile([FromForm] InsigniaNoteDocRequest req, Guid insigniaNoteId) { - var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_INSIGNIA_RECORD"); + var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_INSIGNIA_RECORD"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { @@ -2297,7 +2297,7 @@ namespace BMA.EHR.Insignia.Service.Controllers [HttpPut("preview/receice/{insigniaNoteId:length(36)}"), DisableRequestSizeLimit] public async Task> PreviewReceiceProfile([FromForm] ImportFileRequest req, Guid insigniaNoteId) { - var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_INSIGNIA_RECORD"); + var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_INSIGNIA_RECORD"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { @@ -2429,7 +2429,7 @@ namespace BMA.EHR.Insignia.Service.Controllers [HttpPut("preview/invoice/{insigniaNoteId:length(36)}"), DisableRequestSizeLimit] public async Task> PreviewInvoiceProfile([FromForm] ImportFileRequest req, Guid insigniaNoteId) { - var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_INSIGNIA_RECORD"); + var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_INSIGNIA_RECORD"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { diff --git a/BMA.EHR.Placement.Service/Controllers/NotifyController.cs b/BMA.EHR.Placement.Service/Controllers/NotifyController.cs index 01a40ae3..2fdd8609 100644 --- a/BMA.EHR.Placement.Service/Controllers/NotifyController.cs +++ b/BMA.EHR.Placement.Service/Controllers/NotifyController.cs @@ -62,10 +62,6 @@ namespace BMA.EHR.Placement.Service.Controllers [HttpPost()] public async Task> UpdatePropertyByUser([FromBody] NotiRequest req) { - // var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.Id == req.ReceiverUserId); - // if (profile == null) - // return Error(GlobalMessages.DataNotFound); - await _repositoryNoti.PushNotificationAsync( Guid.Parse(req.ReceiverUserId), req.Subject, @@ -81,10 +77,6 @@ namespace BMA.EHR.Placement.Service.Controllers [HttpPost("keycloak")] public async Task> UpdatePropertyByUserKeycloak([FromBody] NotiRequest req) { - // var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.KeycloakId == req.ReceiverUserId); - // if (profile == null) - // return Error(GlobalMessages.DataNotFound); - var apiUrl = $"{_configuration["API"]}/org/profile/keycloakid/position/" + req.ReceiverUserId; using (var client = new HttpClient()) { @@ -112,18 +104,6 @@ namespace BMA.EHR.Placement.Service.Controllers [HttpPost("profile")] public async Task> UpdatePropertyByUserProfile([FromBody] NotiRequest req) { - // var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.KeycloakId == req.ReceiverUserId); - // if (profile == null) - // return Error(GlobalMessages.DataNotFound); - - // var apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/" + req.ReceiverUserId; - // using (var client = new HttpClient()) - // { - // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - // var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); - // var _res = await client.SendAsync(_req); - // var _result = await _res.Content.ReadAsStringAsync(); - // var org = JsonConvert.DeserializeObject(_result); if (req.ReceiverUserId != null) { await _repositoryNoti.PushNotificationAsync( @@ -136,7 +116,20 @@ namespace BMA.EHR.Placement.Service.Controllers ); } return Success(); - // } + } + + [HttpPost("profiles")] + public async Task> UpdatePropertyByUserProfiles([FromBody] NotisRequest req) + { + await _repositoryNoti.PushNotificationsAsync( + req.ReceiverUserIds.Select(x => Guid.Parse(x)).ToArray(), + req.Subject, + req.Body, + req.Payload, + req.IsSendInbox, + req.IsSendMail + ); + return Success(); } [HttpPut("{id:length(36)}")] @@ -170,11 +163,6 @@ namespace BMA.EHR.Placement.Service.Controllers } return Success(); } - // var profile = await _context.Profiles.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(inbox.CreatedUserId)); - // if (profile == null) - // return Error(GlobalMessages.DataNotFound); - - return Success(); } [HttpPost("cronjob")] diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs index 20d533d4..42dfbc66 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementAppointmentController.cs @@ -1,6 +1,7 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Domain.Common; +using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -481,6 +482,7 @@ namespace BMA.EHR.Placement.Service.Controllers (org.result.child1 == null ? "" : org.result.child1 + "/") + (org.result.root == null ? "" : org.result.root); placementAppointment.OrganizationPositionOld = org.result.position + "-" + placementAppointment.OrganizationOld; + placementAppointment.AmountOld = org.result.salary; } await _context.PlacementAppointments.AddAsync(placementAppointment); await _context.SaveChangesAsync(); @@ -741,5 +743,783 @@ namespace BMA.EHR.Placement.Service.Controllers .ToListAsync(); return Success(appointments); } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-05 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report")] + public async Task> PostReportAppoint([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementAppointments + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-05 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report/delete")] + public async Task> PostReportDeleteAppoint([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementAppointments + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "PENDING"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-05 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportAppointAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementAppointments + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Education = p.EducationOld == null ? "-" : p.EducationOld, + OldOc = (p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld) + "/" + (p.rootOld == null ? "" : p.rootOld), + OldPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld, + OldPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld, + OldPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), + OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + LeaveDate = "", + NewOc = (p.position == null ? "" : p.position) + "/" + (p.root == null ? "" : p.root), + NewPositionType = p.posTypeName == null ? "" : p.posTypeName, + NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName, + NewPositionNumber = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "", + NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-05 คำสั่งแต่งตั้ง + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report/excecute")] + public async Task> PostReportExecuteAppoint([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementAppointments + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "", + position = p.position, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.posTypeName, + positionLevel = p.posLevelName, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + posmasterId = p.posmasterId, + positionId = p.positionId, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-06 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("slip/report")] + public async Task> PostReportSlip([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementAppointments + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-06 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("slip/report/delete")] + public async Task> PostReportDeleteSlip([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementAppointments + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "PENDING"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-06 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("slip/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReporSlipAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementAppointments + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Education = p.EducationOld == null ? "-" : p.EducationOld, + OldOc = (p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld) + "/" + (p.rootOld == null ? "" : p.rootOld), + OldPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld, + OldPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld, + OldPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), + OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + LeaveDate = "", + NewOc = (p.position == null ? "" : p.position) + "/" + (p.root == null ? "" : p.root), + NewPositionType = p.posTypeName == null ? "" : p.posTypeName, + NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName, + NewPositionNumber = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "", + NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-06 เลื่อนข้าราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("slip/report/excecute")] + public async Task> PostReportExecuteSlip([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementAppointments + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "", + position = p.position, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.posTypeName, + positionLevel = p.posLevelName, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + posmasterId = p.posmasterId, + positionId = p.positionId, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-07 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("move/report")] + public async Task> PostReportMove([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementAppointments + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-07 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("move/report/delete")] + public async Task> PostReportDeleteMove([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementAppointments + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "PENDING"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-07 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("move/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReporMoveAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementAppointments + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Education = p.EducationOld == null ? "-" : p.EducationOld, + OldOc = (p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld) + "/" + (p.rootOld == null ? "" : p.rootOld), + OldPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld, + OldPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld, + OldPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), + OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + LeaveDate = "", + NewOc = (p.position == null ? "" : p.position) + "/" + (p.root == null ? "" : p.root), + NewPositionType = p.posTypeName == null ? "" : p.posTypeName, + NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName, + NewPositionNumber = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "", + NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-07 ย้ายข้าราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("move/report/excecute")] + public async Task> PostReportExecuteMove([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementAppointments + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "", + position = p.position, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.posTypeName, + positionLevel = p.posLevelName, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + posmasterId = p.posmasterId, + positionId = p.positionId, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-22 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("employee-appoint/report")] + public async Task> PostReportEmployeeAppoint([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementAppointments + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.type == "EMPLOYEE") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-22 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("employee-appoint/report/delete")] + public async Task> PostReportDeleteEmployeeAppoint([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementAppointments + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.type == "EMPLOYEE") + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "PENDING"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-22 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("employee-appoint/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportEmployeeAppointAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementAppointments + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + // .Where(x => x.type == "EMPLOYEE") + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + OldOrganization = (p.positionOld == null ? "" : p.positionOld) + "/" + (p.OrganizationOld == null ? "" : p.OrganizationOld), + OldPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld.ToThaiNumber(), + OldPositionNumber = p.PositionNumberOld == null ? null : p.PositionNumberOld.ToThaiNumber(), + OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + NewOc = (p.position == null ? "" : p.position) + "/" + (p.root == null ? "" : p.root), + NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName.ToThaiNumber(), + NewPositionNumber = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "", + NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-22 คำสั่งปรับระดับชั้นงาน + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("employee-appoint/report/excecute")] + public async Task> PostReportExecuteEmployeeAppoint([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementAppointments + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "", + position = p.position, + positionType = p.posTypeName, + positionLevel = p.posLevelName, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + posmasterId = p.posmasterId, + positionId = p.positionId, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-current"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-24 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("employee-move/report")] + public async Task> PostReportEmployeeMove([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementAppointments + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.type == "EMPLOYEE") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-24 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("employee-move/report/delete")] + public async Task> PostReportDeleteEmployeeMove([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementAppointments + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.type == "EMPLOYEE") + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "PENDING"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-24 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("employee-move/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportEmployeeMoveAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementAppointments + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + // .Where(x => x.type == "EMPLOYEE") + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + OldOc = (p.positionOld == null ? "" : p.positionOld) + "/" + (p.OrganizationOld == null ? "" : p.OrganizationOld), + OldPositionNumber = p.PositionNumberOld == null ? null : p.PositionNumberOld.ToThaiNumber(), + OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + NewOc = (p.position == null ? "" : p.position) + "/" + (p.root == null ? "" : p.root), + NewPositionNumber = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "", + NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-24 คำสั่งย้ายลูกจ้างประจำ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("employee-move/report/excecute")] + public async Task> PostReportExecuteEmployeeMove([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementAppointments + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "", + position = p.position, + positionType = p.posTypeName, + positionLevel = p.posLevelName, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + posmasterId = p.posmasterId, + positionId = p.positionId, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-current"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } } } diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index 4700c31f..339c8281 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -2,7 +2,6 @@ using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Extensions; -using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -12,13 +11,9 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Swashbuckle.AspNetCore.Annotations; using System.Security.Claims; -using System.Security.Cryptography; -using Microsoft.Extensions.Configuration; using System.Net.Http.Headers; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Microsoft.AspNetCore.Http.HttpResults; -using System.Drawing.Drawing2D; namespace BMA.EHR.Placement.Service.Controllers { @@ -147,10 +142,16 @@ namespace BMA.EHR.Placement.Service.Controllers { var data = await _context.PlacementProfiles.Where(x => x.Placement.Id == examId).Select(x => new { + Id = x.Id, PersonalId = x.Id, + x.profileId, Avatar = x.ProfileImg == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.ProfileImg.Id, FullName = $"{x.Prefix}{x.Firstname} {x.Lastname}", + Prefix = x.Prefix, + Firstname = x.Firstname, + Lastname = x.Lastname, IdCard = x.CitizenId, + CitizenId = x.CitizenId, ExamNumber = x.ExamNumber, posmasterId = x.posmasterId, root = x.root, @@ -194,10 +195,16 @@ namespace BMA.EHR.Placement.Service.Controllers { var _data = new { + p.Id, p.PersonalId, Avatar = p.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(p.Avatar), p.FullName, + p.Prefix, + p.Firstname, + p.Lastname, p.IdCard, + p.CitizenId, + p.profileId, p.ExamNumber, p.posmasterId, p.root, @@ -275,10 +282,16 @@ namespace BMA.EHR.Placement.Service.Controllers .Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))) .Select(x => new { + Id = x.Id, PersonalId = x.Id, + x.profileId, Avatar = x.ProfileImg == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.ProfileImg.Id, FullName = $"{x.Prefix}{x.Firstname} {x.Lastname}", + Prefix = x.Prefix, + Firstname = x.Firstname, + Lastname = x.Lastname, IdCard = x.CitizenId, + CitizenId = x.CitizenId, ExamNumber = x.ExamNumber, posmasterId = x.posmasterId, root = x.root, @@ -322,10 +335,16 @@ namespace BMA.EHR.Placement.Service.Controllers { var _data = new { + p.Id, p.PersonalId, Avatar = p.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(p.Avatar), p.FullName, + p.Prefix, + p.Firstname, + p.Lastname, p.IdCard, + p.CitizenId, + p.profileId, p.ExamNumber, p.posmasterId, p.root, @@ -599,7 +618,8 @@ namespace BMA.EHR.Placement.Service.Controllers Total = x.PlacementProfiles.Count(), UnContain = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "UN-CONTAIN").Count(), PrepareContain = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN").Count(), - Contain = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "CONTAIN").Count(), + Report = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "REPORT").Count(), + Done = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "DONE").Count(), Disclaim = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "DISCLAIM").Count(), }).FirstOrDefaultAsync(); if (placement == null) @@ -643,7 +663,8 @@ namespace BMA.EHR.Placement.Service.Controllers Total = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Count(), UnContain = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "UN-CONTAIN").Count(), PrepareContain = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN").Count(), - Contain = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "CONTAIN").Count(), + Report = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "REPORT").Count(), + Done = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "DONE").Count(), Disclaim = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "DISCLAIM").Count(), }).FirstOrDefaultAsync(); if (placement == null) @@ -1440,11 +1461,1042 @@ namespace BMA.EHR.Placement.Service.Controllers { var position = await _context.PlacementProfiles .Where(x => x.posmasterId != null) - .Where(x => x.PlacementStatus != "CONTAIN") + .Where(x => x.PlacementStatus != "DONE" && x.PlacementStatus != "REPORT") .Select(x => x.posmasterId) .ToListAsync(); return Success(position); } + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-01 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("recruit/report")] + public async Task> PostReportRecruit([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementProfiles + // .Include(x => x.Placement) + // .ThenInclude(x => x.PlacementType) + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") + // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOINTED") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.PlacementStatus = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-01 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("recruit/report/delete")] + public async Task> PostReportDeleteRecruit([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementProfiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.PlacementStatus.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.PlacementStatus = "PREPARE-CONTAIN"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-01 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("recruit/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportRecruitAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementProfiles + .Include(x => x.Placement) + .Include(x => x.PlacementEducations) + // .ThenInclude(x => x.PlacementType) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") + // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOINTED") + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "" : + p.PlacementEducations.FirstOrDefault().Degree, + PositionName = p.positionName == null ? "" : p.positionName, + ExamNumber = p.ExamNumber == null ? "0" : p.ExamNumber.Value.ToString().ToThaiNumber(), + PlacementName = $"{p.Placement.Name.ToThaiNumber()} ครั้งที่ {p.Placement.Round.ToThaiNumber()}/{p.Placement.Year.ToThaiYear().ToString().ToThaiNumber()}", + Oc = (p.positionName == null ? "" : p.positionName) + "/" + (p.root == null ? "" : p.root), + PositionType = p.posTypeName == null ? "" : p.posTypeName, + PositionLevel = p.posLevelName == null ? "" : p.posLevelName, + PositionNumber = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "", + Salary = r.Amount == null ? "0" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber().ToThaiNumber(), + AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-01 บรรจุและแต่งตั้งผู้สอบแข่งขันได้ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("recruit/report/excecute")] + public async Task> PostReportExecuteRecruit([FromBody] ReportExecuteRequest req) + { + try + { + var placementProfile = await _context.PlacementProfiles + .Include(x => x.PlacementCertificates) + .Include(x => x.PlacementEducations) + .ThenInclude(x => x.EducationLevel) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + + if (placementProfile == null) + return NotFound(); + + var resultData = (from p in placementProfile + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + bodyProfile = new + { + rank = string.Empty, + prefix = p.Prefix == null ? string.Empty : p.Prefix, + firstName = p.Firstname == null ? string.Empty : p.Firstname, + lastName = p.Lastname == null ? string.Empty : p.Lastname, + citizenId = p.CitizenId == null ? string.Empty : p.CitizenId, + position = p.positionName == null ? string.Empty : p.positionName, + posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId, + posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId, + email = p.Email == null ? string.Empty : p.Email, + phone = p.MobilePhone == null ? string.Empty : p.MobilePhone, + keycloak = string.Empty, + isProbation = true, + isLeave = false, + dateRetire = (DateTime?)null, + dateAppoint = r.commandAffectDate, + dateStart = r.commandAffectDate, + govAgeAbsent = 0, + govAgePlus = 0, + birthDate = p.DateOfBirth == null ? (DateTime?)null : p.DateOfBirth, + reasonSameDate = (DateTime?)null, + ethnicity = p.Race == null ? string.Empty : p.Race, + telephoneNumber = p.Telephone == null ? string.Empty : p.Telephone, + nationality = p.Nationality == null ? string.Empty : p.Nationality, + gender = p.Gender == null ? string.Empty : p.Gender, + relationship = p.Relationship == null ? string.Empty : p.Relationship, + religion = p.Religion == null ? string.Empty : p.Religion, + bloodGroup = string.Empty, + registrationAddress = p.RegistAddress == null ? string.Empty : p.RegistAddress, + registrationProvinceId = (String?)null, + registrationDistrictId = (String?)null, + registrationSubDistrictId = (String?)null, + registrationZipCode = p.RegistZipCode == null ? string.Empty : p.RegistZipCode, + currentAddress = p.CurrentAddress == null ? string.Empty : p.CurrentAddress, + currentProvinceId = (String?)null, + currentDistrictId = (String?)null, + currentSubDistrictId = (String?)null, + currentZipCode = p.CurrentZipCode == null ? string.Empty : p.CurrentZipCode + }, + bodyEducations = p.PlacementEducations.Select(e => new + { + profileId = string.Empty, + country = e.Country ?? string.Empty, + degree = e.Degree ?? string.Empty, + duration = e.Duration ?? string.Empty, + durationYear = e.DurationYear ?? null, + field = e.Field ?? string.Empty, + finishDate = e.FinishDate ?? null, + fundName = e.FundName ?? string.Empty, + gpa = e.Gpa ?? string.Empty, + institute = e.Institute ?? string.Empty, + other = e.Other ?? string.Empty, + startDate = e.StartDate ?? null, + endDate = e.EndDate ?? null, + educationLevel = e.EducationLevel?.Name ?? string.Empty, + educationLevelId = e.EducationLevel?.Id.ToString() ?? string.Empty, + positionPath = e.PositionPath?.Name ?? string.Empty, + positionPathId = e.PositionPath?.Id.ToString() ?? string.Empty, + isDate = e.IsDate ?? false, + isEducation = e.IsEducation ?? false, + note = e.Other ?? string.Empty + }).ToList(), + bodyCertificates = p.PlacementCertificates.Select(e => new + { + profileId = string.Empty, + expireDate = e.ExpireDate ?? null, + issueDate = e.IssueDate ?? null, + certificateNo = e.CertificateNo ?? string.Empty, + certificateType = e.CertificateType ?? string.Empty, + issuer = e.Issuer ?? string.Empty + }).ToList(), + bodySalarys = new + { + profileId = string.Empty, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "", + position = p.positionName == null ? string.Empty : p.positionName, + positionLine = string.Empty, + positionPathSide = string.Empty, + positionExecutive = string.Empty, + positionType = p.posTypeName == null ? string.Empty : p.posTypeName, + positionLevel = p.posLevelName == null ? string.Empty : p.posLevelName, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc + }, + bodyPosition = new + { + posmasterId = p.posmasterId, + positionId = p.positionId + } + }).ToList(); + + var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl); + var _res = await client.PostAsJsonAsync(apiUrl, new + { + data = resultData + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + placementProfile.ForEach(profile => profile.PlacementStatus = "DONE"); + await _context.SaveChangesAsync(); + } + } + + return Success(); + } + catch + { + throw; + } + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-02 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("candidate/report")] + public async Task> PostReportCandidate([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementProfiles + // .Include(x => x.Placement) + // .ThenInclude(x => x.PlacementType) + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") + // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOINTED") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.PlacementStatus = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-02 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("candidate/report/delete")] + public async Task> PostReportDeleteCandidate([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementProfiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.PlacementStatus.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.PlacementStatus = "PREPARE-CONTAI"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-02 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("candidate/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportCandidateAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementProfiles + .Include(x => x.Placement) + .Include(x => x.PlacementEducations) + // .ThenInclude(x => x.PlacementType) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") + // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOINTED") + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "" : + p.PlacementEducations.FirstOrDefault().Degree, + PositionName = p.positionName == null ? "" : p.positionName, + ExamNumber = p.ExamNumber == null ? "0" : p.ExamNumber.Value.ToString().ToThaiNumber(), + PlacementName = $"{p.Placement.Name.ToThaiNumber()} ครั้งที่ {p.Placement.Round.ToThaiNumber()}/{p.Placement.Year.ToThaiYear().ToString().ToThaiNumber()}", + Oc = (p.positionName == null ? "" : p.positionName) + "/" + (p.root == null ? "" : p.root), + PositionType = p.posTypeName == null ? "" : p.posTypeName, + PositionLevel = p.posLevelName == null ? "" : p.posLevelName, + PositionNumber = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "", + Salary = r.Amount == null ? "0" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber().ToThaiNumber(), + AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-02 บรรจุและแต่งตั้งผู้ได้รับคัดเลือก + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("candidate/report/excecute")] + public async Task> PostReportExecuteCandidate([FromBody] ReportExecuteRequest req) + { + try + { + var placementProfile = await _context.PlacementProfiles + .Include(x => x.PlacementCertificates) + .Include(x => x.PlacementEducations) + .ThenInclude(x => x.EducationLevel) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + + if (placementProfile == null) + return NotFound(); + + var resultData = (from p in placementProfile + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + bodyProfile = new + { + rank = string.Empty, + prefix = p.Prefix == null ? string.Empty : p.Prefix, + firstName = p.Firstname == null ? string.Empty : p.Firstname, + lastName = p.Lastname == null ? string.Empty : p.Lastname, + citizenId = p.CitizenId == null ? string.Empty : p.CitizenId, + position = p.positionName == null ? string.Empty : p.positionName, + posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId, + posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId, + email = p.Email == null ? string.Empty : p.Email, + phone = p.MobilePhone == null ? string.Empty : p.MobilePhone, + keycloak = string.Empty, + isProbation = true, + isLeave = false, + dateRetire = (DateTime?)null, + dateAppoint = r.commandAffectDate, + dateStart = r.commandAffectDate, + govAgeAbsent = 0, + govAgePlus = 0, + birthDate = p.DateOfBirth == null ? (DateTime?)null : p.DateOfBirth, + reasonSameDate = (DateTime?)null, + ethnicity = p.Race == null ? string.Empty : p.Race, + telephoneNumber = p.Telephone == null ? string.Empty : p.Telephone, + nationality = p.Nationality == null ? string.Empty : p.Nationality, + gender = p.Gender == null ? string.Empty : p.Gender, + relationship = p.Relationship == null ? string.Empty : p.Relationship, + religion = p.Religion == null ? string.Empty : p.Religion, + bloodGroup = string.Empty, + registrationAddress = p.RegistAddress == null ? string.Empty : p.RegistAddress, + registrationProvinceId = (String?)null, + registrationDistrictId = (String?)null, + registrationSubDistrictId = (String?)null, + registrationZipCode = p.RegistZipCode == null ? string.Empty : p.RegistZipCode, + currentAddress = p.CurrentAddress == null ? string.Empty : p.CurrentAddress, + currentProvinceId = (String?)null, + currentDistrictId = (String?)null, + currentSubDistrictId = (String?)null, + currentZipCode = p.CurrentZipCode == null ? string.Empty : p.CurrentZipCode + }, + bodyEducations = p.PlacementEducations.Select(e => new + { + profileId = string.Empty, + country = e.Country ?? string.Empty, + degree = e.Degree ?? string.Empty, + duration = e.Duration ?? string.Empty, + durationYear = e.DurationYear ?? null, + field = e.Field ?? string.Empty, + finishDate = e.FinishDate ?? null, + fundName = e.FundName ?? string.Empty, + gpa = e.Gpa ?? string.Empty, + institute = e.Institute ?? string.Empty, + other = e.Other ?? string.Empty, + startDate = e.StartDate ?? null, + endDate = e.EndDate ?? null, + educationLevel = e.EducationLevel?.Name ?? string.Empty, + educationLevelId = e.EducationLevel?.Id.ToString() ?? string.Empty, + positionPath = e.PositionPath?.Name ?? string.Empty, + positionPathId = e.PositionPath?.Id.ToString() ?? string.Empty, + isDate = e.IsDate ?? false, + isEducation = e.IsEducation ?? false, + note = e.Other ?? string.Empty + }).ToList(), + bodyCertificates = p.PlacementCertificates.Select(e => new + { + profileId = string.Empty, + expireDate = e.ExpireDate ?? null, + issueDate = e.IssueDate ?? null, + certificateNo = e.CertificateNo ?? string.Empty, + certificateType = e.CertificateType ?? string.Empty, + issuer = e.Issuer ?? string.Empty + }).ToList(), + bodySalarys = new + { + profileId = string.Empty, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "", + position = p.positionName == null ? string.Empty : p.positionName, + positionLine = string.Empty, + positionPathSide = string.Empty, + positionExecutive = string.Empty, + positionType = p.posTypeName == null ? string.Empty : p.posTypeName, + positionLevel = p.posLevelName == null ? string.Empty : p.posLevelName, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc + }, + bodyPosition = new + { + posmasterId = p.posmasterId, + positionId = p.positionId + } + }).ToList(); + + var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl); + var _res = await client.PostAsJsonAsync(apiUrl, new + { + data = resultData + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + placementProfile.ForEach(profile => profile.PlacementStatus = "DONE"); + await _context.SaveChangesAsync(); + } + } + + // // update placementstatus + // placementProfile.ForEach(profile => profile.PlacementStatus = "DONE"); + // await _context.SaveChangesAsync(); + return Success(); + } + catch + { + throw; + } + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-03 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report")] + public async Task> PostReportAppoint([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementProfiles + // .Include(x => x.Placement) + // .ThenInclude(x => x.PlacementType) + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Placement!.PlacementType!.Name == "แต่งตั้งข้าราชการ") + // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOIN") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.PlacementStatus = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-03 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report/delete")] + public async Task> PostReportDeleteAppoint([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementProfiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.PlacementStatus.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.PlacementStatus = "PREPARE-CONTAIN"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-03 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportAppointAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementProfiles + .Include(x => x.PlacementEducations) + // .ThenInclude(x => x.PlacementType) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + // .Where(x => x.Placement!.PlacementType!.Name == "แต่งตั้งข้าราชการ") + // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOIN") + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "" : + p.PlacementEducations.FirstOrDefault().Degree, + OldOc = (p.positionNameOld == null ? "" : p.positionNameOld) + "/" + (p.rootOld == null ? "" : p.rootOld), + OldPositionType = p.posTypeNameOld == null ? "" : p.posTypeNameOld, + OldPositionLevel = p.posLevelNameOld == null ? "" : p.posLevelNameOld, + OldPositionNumber = p.posMasterNoOld == null ? "" : + p.nodeOld == "4" ? $"{p.child4ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "3" ? $"{p.child3ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "2" ? $"{p.child2ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "1" ? $"{p.child1ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "0" ? $"{p.rootShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : "", + OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + NewOc = (p.positionName == null ? "" : p.positionName) + "/" + (p.root == null ? "" : p.root), + NewPositionType = p.posTypeName == null ? "" : p.posTypeName, + NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName, + NewPositionNumber = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "", + NewSalary = p.Amount == null ? "" : p.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-03 แต่งตั้งข้าราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report/excecute")] + public async Task> PostReportExecuteAppoint([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementProfiles + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "", + position = p.positionName, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.posTypeName, + positionLevel = p.posLevelName, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + posmasterId = p.posmasterId, + positionId = p.positionId, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.PlacementStatus = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-04 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("move/report")] + public async Task> PostReportMove([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementProfiles + // .Include(x => x.Placement) + // .ThenInclude(x => x.PlacementType) + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Placement!.PlacementType!.Name == "ย้ายข้าราชการ") + // .Where(x => x.typeCommand.Trim().ToUpper() == "MOVE") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.PlacementStatus = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-04 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("move/report/delete")] + public async Task> PostReportDeleteMove([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementProfiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.PlacementStatus.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.PlacementStatus = "PREPARE-CONTAIN"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-04 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("move/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportMoveAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementProfiles + .Include(x => x.PlacementEducations) + // .ThenInclude(x => x.PlacementType) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + // .Where(x => x.Placement!.PlacementType!.Name == "แต่งตั้งข้าราชการ") + // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOIN") + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "" : + p.PlacementEducations.FirstOrDefault().Degree, + OldOc = (p.positionNameOld == null ? "" : p.positionNameOld) + "/" + (p.rootOld == null ? "" : p.rootOld), + OldPositionType = p.posTypeNameOld == null ? "" : p.posTypeNameOld, + OldPositionLevel = p.posLevelNameOld == null ? "" : p.posLevelNameOld, + OldPositionNumber = p.posMasterNoOld == null ? "" : + p.nodeOld == "4" ? $"{p.child4ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "3" ? $"{p.child3ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "2" ? $"{p.child2ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "1" ? $"{p.child1ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "0" ? $"{p.rootShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : "", + OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + NewOc = (p.positionName == null ? "" : p.positionName) + "/" + (p.root == null ? "" : p.root), + NewPositionType = p.posTypeName == null ? "" : p.posTypeName, + NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName, + NewPositionNumber = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "", + NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-04 ย้ายข้าราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("move/report/excecute")] + public async Task> PostReportExecuteMove([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementProfiles + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "", + position = p.positionName, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.posTypeName, + positionLevel = p.posLevelName, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + posmasterId = p.posmasterId, + positionId = p.positionId, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.PlacementStatus = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-39 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("slip/report")] + public async Task> PostReportSlip([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementProfiles + // .Include(x => x.Placement) + // .ThenInclude(x => x.PlacementType) + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Placement!.PlacementType!.Name == "เลื่อนข้าราชการ") + // .Where(x => x.typeCommand.Trim().ToUpper() == "SLIP") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.PlacementStatus = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-39 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("slip/report/delete")] + public async Task> PostReportDeleteSlip([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementProfiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.PlacementStatus.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.PlacementStatus = "PREPARE-CONTAIN"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-39 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("slip/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportSlipAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementProfiles + .Include(x => x.PlacementEducations) + // .ThenInclude(x => x.PlacementType) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + // .Where(x => x.Placement!.PlacementType!.Name == "เลื่อนข้าราชการ") + // .Where(x => x.typeCommand.Trim().ToUpper() == "SLIP") + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "" : + p.PlacementEducations.FirstOrDefault().Degree, + OldOc = (p.positionNameOld == null ? "" : p.positionNameOld) + "/" + (p.rootOld == null ? "" : p.rootOld), + OldPositionType = p.posTypeNameOld == null ? "" : p.posTypeNameOld, + OldPositionLevel = p.posLevelNameOld == null ? "" : p.posLevelNameOld, + OldPositionNumber = p.posMasterNoOld == null ? "" : + p.nodeOld == "4" ? $"{p.child4ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "3" ? $"{p.child3ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "2" ? $"{p.child2ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "1" ? $"{p.child1ShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : + p.nodeOld == "0" ? $"{p.rootShortNameOld}{p.posMasterNoOld}".ToThaiNumber() : "", + OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + NewOc = (p.positionName == null ? "" : p.positionName) + "/" + (p.root == null ? "" : p.root), + NewPositionType = p.posTypeName == null ? "" : p.posTypeName, + NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName, + NewPositionNumber = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "", + NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-39 เลื่อนข้าราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("slip/report/excecute")] + public async Task> PostReportExecuteSlip([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementProfiles + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "", + position = p.positionName, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.posTypeName, + positionLevel = p.posLevelName, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + posmasterId = p.posmasterId, + positionId = p.positionId, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.PlacementStatus = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } } } diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs index 8ad0b7fa..02dfe7d6 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementOfficerController.cs @@ -1,6 +1,7 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Domain.Common; +using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -108,6 +109,8 @@ namespace BMA.EHR.Placement.Service.Controllers .Select(p => new { p.Id, + p.citizenId, + p.profileId, p.prefix, p.firstName, p.lastName, @@ -566,5 +569,143 @@ namespace BMA.EHR.Placement.Service.Controllers return Success(); } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-15 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report")] + public async Task> PostReport([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementOfficers + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-15 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/delete")] + public async Task> PostReportDelete([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementOfficers + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "APPROVE"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-15 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementOfficers + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + PositionName = p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld, + Organization = p.Organization == null ? "" : p.Organization, + StartDate = p.DateStart == null ? "" : p.DateStart.Value.ToThaiShortDate2().ToThaiNumber(), + EndDate = p.DateEnd == null ? "" : p.DateEnd.Value.ToThaiShortDate2().ToThaiNumber(), + Reason = p.Reason == null ? "" : p.Reason.ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-15 คำสั่งให้ช่วยราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/excecute")] + public async Task> PostReportExecute([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementOfficers + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.PositionNumberOld, + position = p.PositionOld, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.PositionTypeOld, + positionLevel = p.PositionLevelOld, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } } } diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs index 7bf549b9..a912f42a 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs @@ -1,6 +1,7 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Domain.Common; +using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -878,5 +879,208 @@ namespace BMA.EHR.Placement.Service.Controllers .ToListAsync(); return Success(position); } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-14 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report")] + public async Task> PostReport([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementReceives + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-14 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/delete")] + public async Task> PostReportDelete([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementReceives + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "PENDING"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-14 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementReceives + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Education = p.EducationOld == null ? "-" : p.EducationOld, + OldOc = p.OrganizationPositionOld ?? "", + OldPositionType = p.PositionTypeOld ?? "", + OldPositionLevel = p.PositionLevelOld ?? "", + OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + NewOc = (p.position == null ? "" : p.position) + "/" + (p.root == null ? "" : p.root), + NewPositionType = p.posTypeName == null ? "" : p.posTypeName, + NewPositionLevel = p.posLevelName == null ? "" : p.posLevelName, + NewPositionNumber = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}".ToThaiNumber() : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}".ToThaiNumber() : "", + NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + AppointDate = p.ReportingDate == null ? "" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-14 คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/excecute")] + public async Task> PostReportExecute([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementReceives + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + bodyProfile = new + { + rank = string.Empty, + prefix = p.prefix == null ? string.Empty : p.prefix, + firstName = p.firstName == null ? string.Empty : p.firstName, + lastName = p.lastName == null ? string.Empty : p.lastName, + citizenId = p.citizenId == null ? string.Empty : p.citizenId, + position = p.position == null ? string.Empty : p.position, + posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId, + posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId, + email = (String?)null, + phone = (String?)null, + keycloak = string.Empty, + isProbation = true, + isLeave = false, + dateRetire = (DateTime?)null, + dateAppoint = r.commandAffectDate, + dateStart = r.commandAffectDate, + govAgeAbsent = 0, + govAgePlus = 0, + birthDate = p.DateOfBirth == null ? (DateTime?)null : p.DateOfBirth, + reasonSameDate = (DateTime?)null, + ethnicity = p.Race == null ? string.Empty : p.Race, + telephoneNumber = (String?)null, + nationality = p.Nationality == null ? string.Empty : p.Nationality, + gender = p.Gender == null ? string.Empty : p.Gender, + relationship = p.Relationship == null ? string.Empty : p.Relationship, + religion = p.Religion == null ? string.Empty : p.Religion, + bloodGroup = string.Empty, + registrationAddress = (String?)null, + registrationProvinceId = (String?)null, + registrationDistrictId = (String?)null, + registrationSubDistrictId = (String?)null, + registrationZipCode = (String?)null, + currentAddress = (String?)null, + currentProvinceId = (String?)null, + currentDistrictId = (String?)null, + currentSubDistrictId = (String?)null, + currentZipCode = (String?)null, + }, + bodySalarys = new + { + profileId = string.Empty, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.posMasterNo == null ? "" : + p.node == 4 ? $"{p.child4ShortName}{p.posMasterNo}" : + p.node == 3 ? $"{p.child3ShortName}{p.posMasterNo}" : + p.node == 2 ? $"{p.child2ShortName}{p.posMasterNo}" : + p.node == 1 ? $"{p.child1ShortName}{p.posMasterNo}" : + p.node == 0 ? $"{p.rootShortName}{p.posMasterNo}" : "", + position = p.position == null ? string.Empty : p.position, + positionLine = string.Empty, + positionPathSide = string.Empty, + positionExecutive = string.Empty, + positionType = p.posTypeName == null ? string.Empty : p.posTypeName, + positionLevel = p.posLevelName == null ? string.Empty : p.posLevelName, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc + }, + bodyPosition = new + { + posmasterId = p.posmasterId, + positionId = p.positionId + } + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + //var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; + var apiUrlOrg = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } } } diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs index abb7055c..ff68ddb1 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementRepatriationController.cs @@ -1,6 +1,7 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Domain.Common; +using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -109,6 +110,7 @@ namespace BMA.EHR.Placement.Service.Controllers .Select(p => new { p.Id, + p.citizenId, p.profileId, p.prefix, p.firstName, @@ -473,5 +475,98 @@ namespace BMA.EHR.Placement.Service.Controllers // return Success(); // } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-16 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report")] + public async Task> PostReport([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementRepatriations + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบส่งรายชื่อออกคำสั่ง C-PM-16 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/delete")] + public async Task> PostReportDelete([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementRepatriations + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "APPROVE"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ออกคำสั่ง C-PM-16 คำสั่งส่งตัวกลับ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/excecute")] + public async Task> PostReportExecute([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementRepatriations + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.PositionNumberOld, + position = p.PositionOld, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.PositionTypeOld, + positionLevel = p.PositionLevelOld, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } } } diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs index 000adcf0..65361663 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementTransferController.cs @@ -1,6 +1,7 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Domain.Common; +using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -12,7 +13,6 @@ using Newtonsoft.Json; using Swashbuckle.AspNetCore.Annotations; using System.Net.Http.Headers; using System.Security.Claims; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace BMA.EHR.Placement.Service.Controllers @@ -129,6 +129,23 @@ namespace BMA.EHR.Placement.Service.Controllers p.IsActive, }) .ToListAsync(); + //if (keyword != "") + //{ + // var data = placementTransfers.Where(x => + // (x.OrganizationPositionOld != null && x.OrganizationPositionOld.Contains(keyword)) || + // (x.rootShortNameOld != null && x.rootShortNameOld.Contains(keyword)) || + // (x.PositionNumberOld != null && x.PositionNumberOld.Contains(keyword)) || + // (x.posTypeNameOld != null && x.posTypeNameOld.Contains(keyword)) || + // (x.posLevelNameOld != null && x.posLevelNameOld.Contains(keyword)) || + // (x.Organization != null && x.Organization.Contains(keyword)) + // ) + // .OrderByDescending(x => x.CreatedAt) + // .Skip((page - 1) * pageSize) + // .Take(pageSize) + // .ToList(); + + // placementTransfers = data; + //} return Success(placementTransfers); } } @@ -181,6 +198,7 @@ namespace BMA.EHR.Placement.Service.Controllers .Select(p => new { p.Id, + p.citizenId, p.profileId, p.prefix, p.firstName, @@ -740,5 +758,146 @@ namespace BMA.EHR.Placement.Service.Controllers return Success(); } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-13 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report")] + public async Task> PostReport([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementTransfers + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-13 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/delete")] + public async Task> PostReportDelete([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.PlacementTransfers + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "APPROVE"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-13 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.PlacementTransfers + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Oc = (p.PositionOld == null ? "" : p.PositionOld) + "/" + (p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld), + PositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld, + PositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld, + PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), + Salary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + ReceiveOrganizationName = "", + ActiveDate = p.Date == null ? "" : p.Date.Value.ToThaiShortDate2().ToThaiNumber(), + Reason = p.Reason ?? "", + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-13 คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/excecute")] + public async Task> PostReportExecute([FromBody] ReportExecuteRequest req) + { + var data = await _context.PlacementTransfers + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.PositionNumberOld, + position = p.PositionOld, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.PositionTypeOld, + positionLevel = p.PositionLevelOld, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } } } diff --git a/BMA.EHR.Placement.Service/Requests/NotisRequest.cs b/BMA.EHR.Placement.Service/Requests/NotisRequest.cs new file mode 100644 index 00000000..201bde0a --- /dev/null +++ b/BMA.EHR.Placement.Service/Requests/NotisRequest.cs @@ -0,0 +1,16 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Placement.Service.Requests +{ + public class NotisRequest + { + public string Subject { get; set; } + public string Body { get; set; } + public string Payload { get; set; } + public string[] ReceiverUserIds { get; set; } + public bool IsSendMail { get; set; } + public bool IsSendInbox { get; set; } + public bool IsSendNotification { get; set; } + } +} diff --git a/BMA.EHR.Placement.Service/Requests/ReportAttachmentRequest.cs b/BMA.EHR.Placement.Service/Requests/ReportAttachmentRequest.cs new file mode 100644 index 00000000..75379027 --- /dev/null +++ b/BMA.EHR.Placement.Service/Requests/ReportAttachmentRequest.cs @@ -0,0 +1,25 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Placement.Service.Requests +{ + public class ReportAttachmentRequest + { + public ReportAttachmentRequestObj[] refIds { get; set; } + } + public class ReportAttachmentRequestObj + { + public string? refId { get; set; } + public int? Sequence { get; set; } + public string? CitizenId { get; set; } + public string? Prefix { get; set; } + public string? FirstName { get; set; } + public string? LastName { get; set; } + public double? Amount { get; set; } + public double? PositionSalaryAmount { get; set; } + public double? MouthSalaryAmount { get; set; } + public string? RemarkHorizontal { get; set; } + public string? RemarkVertical { get; set; } + public int CommandYear { get; set; } + } +} diff --git a/BMA.EHR.Placement.Service/Requests/ReportExecuteRequest.cs b/BMA.EHR.Placement.Service/Requests/ReportExecuteRequest.cs new file mode 100644 index 00000000..7718c354 --- /dev/null +++ b/BMA.EHR.Placement.Service/Requests/ReportExecuteRequest.cs @@ -0,0 +1,21 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Placement.Service.Requests +{ + public class ReportExecuteRequest + { + public ReportExecuteRequestObj[] refIds { get; set; } + } + public class ReportExecuteRequestObj + { + public string? refId { get; set; } + public DateTime commandAffectDate { get; set; } + public string? commandNo { get; set; } + public int commandYear { get; set; } + public string? templateDoc { get; set; } + public double? amount { get; set; } + public double? positionSalaryAmount { get; set; } + public double? mouthSalaryAmount { get; set; } + } +} diff --git a/BMA.EHR.Placement.Service/Requests/ReportPersonRequest.cs b/BMA.EHR.Placement.Service/Requests/ReportPersonRequest.cs new file mode 100644 index 00000000..e061f5a1 --- /dev/null +++ b/BMA.EHR.Placement.Service/Requests/ReportPersonRequest.cs @@ -0,0 +1,10 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Placement.Service.Requests +{ + public class ReportPersonRequest + { + public string[] refIds { get; set; } + } +} diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs index 1585fcac..3d365f7c 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementDeceasedController.cs @@ -118,6 +118,7 @@ namespace BMA.EHR.Retirement.Service.Controllers .Select(p => new { p.Id, + p.citizenId, p.profileId, p.prefix, p.firstName, diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs index a3b2ec1a..6a2af848 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementOtherController.cs @@ -1,6 +1,7 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Domain.Common; +using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Retirement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -108,6 +109,7 @@ namespace BMA.EHR.Retirement.Service.Controllers .Select(p => new { p.Id, + p.citizenId, p.profileId, p.prefix, p.firstName, @@ -623,5 +625,306 @@ namespace BMA.EHR.Retirement.Service.Controllers return Success(); } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-08 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report")] + public async Task> PostReportAppoint([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementOthers + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-08 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report/delete")] + public async Task> PostReportDeleteAppoint([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementOthers + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "WAITTING"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-08 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportAppointAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.RetirementOthers + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Education = p.EducationOld == null ? "-" : p.EducationOld, + OldOc = (p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld) + "/" + (p.rootOld == null ? "" : p.rootOld), + OldPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld, + OldPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld, + OldPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), + OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + LeaveDate = "", + NewOc = (p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld) + "/" + (p.rootOld == null ? "" : p.rootOld), + NewPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld, + NewPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld, + NewPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), + NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + AppointDate = p.PositionDate == null ? "" : p.PositionDate.Value.ToThaiShortDate2().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-08 บรรจุและแต่งตั้งข้าราชการกลับเข้ารับราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("appoint/report/excecute")] + public async Task> PostReportExecuteAppoint([FromBody] ReportExecuteRequest req) + { + var data = await _context.RetirementOthers + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + string? _null = null; + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.PositionNumberOld, + position = p.PositionOld, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.PositionTypeOld, + positionLevel = p.PositionLevelOld, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + isLeave = false, + leaveReason = _null, + dateLeave = _null, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-09 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("out/report")] + public async Task> PostReportOut([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementOthers + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-09 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("out/report/delete")] + public async Task> PostReportDeleteOut([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementOthers + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "WAITTING"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-09 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("out/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportOutAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.RetirementOthers + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + No = r.Sequence.ToString().ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Education = p.EducationOld == null ? "-" : p.EducationOld, + OldOc = (p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld) + "/" + (p.rootOld == null ? "" : p.rootOld), + OldPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld, + OldPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld, + OldPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), + OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + LeaveDate = "", + MilitaryDate = p.MilitaryDate == null ? "" : p.MilitaryDate.Value.ToThaiShortDate2().ToThaiNumber(), + NewOc = (p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld) + "/" + (p.rootOld == null ? "" : p.rootOld), + NewPositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld, + NewPositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld, + NewPositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), + NewSalary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + AppointDate = p.PositionDate == null ? "" : p.PositionDate.Value.ToThaiShortDate2().ToThaiNumber(), + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-09 คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("out/report/excecute")] + public async Task> PostReportExecuteOut([FromBody] ReportExecuteRequest req) + { + var data = await _context.RetirementOthers + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + string? _null = null; + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.PositionNumberOld, + position = p.PositionOld, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.PositionTypeOld, + positionLevel = p.PositionLevelOld, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + isLeave = false, + leaveReason = _null, + dateLeave = _null, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } } } diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs index 51c253c8..887cc1f3 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementOutController.cs @@ -1,6 +1,7 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Domain.Common; +using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Retirement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -107,6 +108,7 @@ namespace BMA.EHR.Retirement.Service.Controllers .Select(p => new { p.Id, + p.citizenId, p.profileId, p.prefix, p.firstName, @@ -464,5 +466,102 @@ namespace BMA.EHR.Retirement.Service.Controllers return Success(); } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-18 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report")] + public async Task> PostReport([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-18 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/delete")] + public async Task> PostDeleteReport([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + // .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "APPROVE"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ออกคำสั่ง C-PM-18 คำสั่งให้ออกจากราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/excecute")] + public async Task> PostReportExecuteLeave([FromBody] ReportExecuteRequest req) + { + var data = await _context.RetirementOuts + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.PositionNumberOld, + position = p.PositionOld, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.PositionTypeOld, + positionLevel = p.PositionLevelOld, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + isLeave = true, + leaveReason = "ให้ออกจากราชการ", + dateLeave = r.commandAffectDate, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } } } diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index 5013adeb..a5f7f0c3 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -2,7 +2,6 @@ using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Extensions; -using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.Retirement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -15,8 +14,6 @@ using Newtonsoft.Json.Linq; using Swashbuckle.AspNetCore.Annotations; using System.Net.Http.Headers; using System.Security.Claims; -using System.Security.Cryptography; -using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace BMA.EHR.Retirement.Service.Controllers { @@ -185,6 +182,7 @@ namespace BMA.EHR.Retirement.Service.Controllers .Select(p => new { p.Id, + p.citizenId, p.profileId, p.prefix, p.firstName, @@ -1628,5 +1626,388 @@ $"คำขอลาออกของ {updated.prefix}{updated.firstName} {upda return Success(retirementQuestionnaireQuestion); } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-17 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report")] + public async Task> PostReport([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + /// + /// ลบรายชื่อออกคำสั่ง C-PM-17 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/delete")] + public async Task> PostReportDelete([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "APPROVE"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-17 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.RetirementResigns + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + Seq = r.Sequence.ToString().ToThaiNumber(), + CitizenId = r.CitizenId == null ? "-" : r.CitizenId.ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + PositionName = p.PositionOld ?? "", + Organization = p.OrganizationPositionOld ?? "", + PositionLevel = p.PositionLevelOld ?? "", + PositionType = p.PositionTypeOld ?? "", + PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), + ActiveDate = p.ActiveDate == null ? "" : p.ActiveDate.Value.ToThaiShortDate2().ToThaiNumber(), + Salary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + Remark = p.Reason ?? "", + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-17 คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command/report/excecute")] + public async Task> PostReportExecute([FromBody] ReportExecuteRequest req) + { + var data = await _context.RetirementResigns + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.PositionNumberOld, + position = p.PositionOld, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.PositionTypeOld, + positionLevel = p.PositionLevelOld, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + isLeave = true, + leaveReason = "ลาออกจากราชการ", + dateLeave = r.commandAffectDate, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-23 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("employee/report")] + public async Task> PostReportEmployee([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-23 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("employee/report/delete")] + public async Task> PostReportDeleteEmployee([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "APPROVE"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ออกคำสั่ง C-PM-23 คำสั่งให้ลูกจ้างออกจากราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("employee/report/excecute")] + public async Task> PostReportExecuteEmployee([FromBody] ReportExecuteRequest req) + { + var data = await _context.RetirementResigns + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.PositionNumberOld, + position = p.PositionOld, + positionType = p.PositionTypeOld, + positionLevel = p.PositionLevelOld, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + isLeave = true, + leaveReason = "ลาออกจากราชการ", + dateLeave = r.commandAffectDate, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-employee-leave"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-41 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("leave-cancel/report")] + public async Task> PostReportLeaveCancel([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// ลบรายชื่อออกคำสั่ง C-PM-41 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("leave-cancel/report/delete")] + public async Task> PostReportDeleteLeaveCancel([FromBody] ReportPersonRequest req) + { + var placementProfiles = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + placementProfiles.ForEach(profile => profile.Status = "DONECANCEL"); + await _context.SaveChangesAsync(); + return Success(); + } + /// + /// เอกสารแนบท้าย C-PM-41 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("leave-cancel/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportLeaveCancelAttachment([FromBody] ReportAttachmentRequest req) + { + try + { + var report_data = (from p in _context.RetirementResigns + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToList() + join r in req.refIds + on p.Id.ToString() equals r.refId + orderby r.Sequence + select new + { + Seq = r.Sequence.ToString().ToThaiNumber(), + CitizenId = r.CitizenId == null ? "-" : r.CitizenId.ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + PositionName = p.PositionOld ?? "", + Organization = p.OrganizationPositionOld ?? "", + PositionLevel = p.PositionLevelOld ?? "", + PositionType = p.PositionTypeOld ?? "", + PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), + ActiveDate = p.ActiveDate == null ? "" : p.ActiveDate.Value.ToThaiShortDate2().ToThaiNumber(), + Salary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + Remark = p.Reason ?? "", + RemarkHorizontal = r.RemarkHorizontal, + RemarkVertical = r.RemarkVertical, + }).ToList(); + return Success(report_data); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-41 คำสั่งยกเลิกการลาออก + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("leave-cancel/report/excecute")] + public async Task> PostReportExecuteLeaveCancel([FromBody] ReportExecuteRequest req) + { + var data = await _context.RetirementResigns + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + string? _null = null; + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + date = r.commandAffectDate, + amount = r.amount, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + posNo = p.PositionNumberOld, + position = p.PositionOld, + positionLine = "", + positionPathSide = "", + positionExecutive = "", + positionType = p.PositionTypeOld, + positionLevel = p.PositionLevelOld, + refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}", + templateDoc = r.templateDoc, + isLeave = false, + leaveReason = _null, + dateLeave = _null, + }).ToList(); + + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.Status = "DONEREJECT"); + await _context.SaveChangesAsync(); + } + } + return Success(); + } } } diff --git a/BMA.EHR.Retirement.Service/Requests/ReportAttachmentRequest.cs b/BMA.EHR.Retirement.Service/Requests/ReportAttachmentRequest.cs new file mode 100644 index 00000000..2e71ceda --- /dev/null +++ b/BMA.EHR.Retirement.Service/Requests/ReportAttachmentRequest.cs @@ -0,0 +1,25 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Retirement.Service.Requests +{ + public class ReportAttachmentRequest + { + public ReportAttachmentRequestObj[] refIds { get; set; } + } + public class ReportAttachmentRequestObj + { + public string? refId { get; set; } + public int? Sequence { get; set; } + public string? CitizenId { get; set; } + public string? Prefix { get; set; } + public string? FirstName { get; set; } + public string? LastName { get; set; } + public double? Amount { get; set; } + public double? PositionSalaryAmount { get; set; } + public double? MouthSalaryAmount { get; set; } + public string? RemarkHorizontal { get; set; } + public string? RemarkVertical { get; set; } + public int CommandYear { get; set; } + } +} diff --git a/BMA.EHR.Retirement.Service/Requests/ReportExecuteRequest.cs b/BMA.EHR.Retirement.Service/Requests/ReportExecuteRequest.cs new file mode 100644 index 00000000..c9d87113 --- /dev/null +++ b/BMA.EHR.Retirement.Service/Requests/ReportExecuteRequest.cs @@ -0,0 +1,21 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Retirement.Service.Requests +{ + public class ReportExecuteRequest + { + public ReportExecuteRequestObj[] refIds { get; set; } + } + public class ReportExecuteRequestObj + { + public string? refId { get; set; } + public DateTime commandAffectDate { get; set; } + public string? commandNo { get; set; } + public int commandYear { get; set; } + public string? templateDoc { get; set; } + public double? amount { get; set; } + public double? positionSalaryAmount { get; set; } + public double? mouthSalaryAmount { get; set; } + } +} diff --git a/BMA.EHR.Retirement.Service/Requests/ReportPersonRequest.cs b/BMA.EHR.Retirement.Service/Requests/ReportPersonRequest.cs new file mode 100644 index 00000000..5a6136be --- /dev/null +++ b/BMA.EHR.Retirement.Service/Requests/ReportPersonRequest.cs @@ -0,0 +1,10 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Retirement.Service.Requests +{ + public class ReportPersonRequest + { + public string[] refIds { get; set; } + } +}