From 7d2be029b6dde4438c6878264c68f0c6e9568547 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 11 Jun 2026 11:42:18 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1?= =?UTF-8?q?=E0=B9=88=E0=B8=87=E0=B8=AD=E0=B8=99=E0=B8=B8=E0=B8=8D=E0=B8=B2?= =?UTF-8?q?=E0=B8=95=E0=B9=83=E0=B8=AB=E0=B9=89=E0=B8=A5=E0=B8=B2=E0=B8=AD?= =?UTF-8?q?=E0=B8=AD=E0=B8=81=E0=B9=84=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=97?= =?UTF-8?q?=E0=B8=AB=E0=B8=B2=E0=B8=A3=20#248?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 +- .../Controllers/RetirementResignController.cs | 188 ++++++++++++++++++ 2 files changed, 195 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7391825f..f60d8ec1 100644 --- a/.gitignore +++ b/.gitignore @@ -373,4 +373,10 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd + +# VS Code C# Dev Kit cache +*.lscache + +# Claude Code +.claude/ \ No newline at end of file diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs index 2dd451ab..03871f9f 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementResignController.cs @@ -2975,6 +2975,194 @@ namespace BMA.EHR.Retirement.Service.Controllers return Success(); } + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-48 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command48/report")] + public async Task> PostReport48([FromBody] ReportPersonRequest req) + { + var resigns = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + resigns.ForEach(profile => profile.Status = req.status.Trim().ToUpper()); + await _context.SaveChangesAsync(); + return Success(); + } + /// + /// ลบรายชื่อออกคำสั่ง C-PM-48 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command48/report/delete")] + public async Task> PostReportDelete48([FromBody] ReportPersonRequest req) + { + var resigns = await _context.RetirementResigns + .Where(x => req.refIds.Contains(x.Id.ToString())) + .Where(x => x.Status.ToUpper() == "REPORT") + .ToListAsync(); + resigns.ForEach(profile => profile.Status = "APPROVE"); + await _context.SaveChangesAsync(); + return Success(); + } + + /// + /// เอกสารแนบท้าย C-PM-48 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command48/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportAttachment48([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 + { + No = 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 == null ? "-" : r.RemarkHorizontal.ToThaiNumber(), + RemarkVertical = r.RemarkVertical == null ? "-" : r.RemarkVertical.ToThaiNumber() + }).ToList(); + + var result = new List(); + + foreach (var r in report_data) + { + result.Add(r); + string? _null = null; + if (r.RemarkHorizontal != null && r.RemarkHorizontal != "") + { + result.Add(new + { + No = _null, + FullName = r.RemarkHorizontal, + CitizenId = _null, + PositionName = _null, + Organization = _null, + PositionLevel = _null, + PositionType = _null, + PositionNumber = _null, + ActiveDate = _null, + Salary = _null, + Remark = _null, + RemarkHorizontal = _null, + RemarkVertical = _null, + }); + } + } + return Success(result); + } + catch + { + throw; + } + } + + /// + /// ออกคำสั่ง C-PM-48 คำสั่งอนุญาตให้ลาออกไปรับราชการทหาร + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command48/report/excecute")] + public async Task> PostReportExecute48([FromBody] ReportExecuteRequest req) + { + var data = await _context.RetirementResigns + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + // Task #224 ปรับให้เป็น process ที่ควรบันทึกตามลำดับ + data.ForEach(profile => profile.Status = "DONE"); + await _context.SaveChangesAsync(); + + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.profileId, + amount = r.amount, + amountSpecial = r.amountSpecial, + positionSalaryAmount = r.positionSalaryAmount, + mouthSalaryAmount = r.mouthSalaryAmount, + positionExecutive = p.PositionExecutiveOld, + positionExecutiveField = p.positionExecutiveFieldOld, + positionArea = p.positionAreaOld, + positionType = p.PositionTypeOld, + positionLevel = p.PositionLevelOld, + isLeave = p.IsCancel == true ? false : true, + leaveReason = p.ReasonResign == "อื่น ๆ" + ? string.IsNullOrWhiteSpace(p.Remark) ? p.ReasonResign : $"{p.ReasonResign}({p.Remark})" + : p.ReasonResign, + dateLeave = r.commandDateAffect, + commandId = r.commandId, + isGovernment = false, + orgRoot = p.rootOld, + orgChild1 = p.child1Old, + orgChild2 = p.child2Old, + orgChild3 = p.child3Old, + orgChild4 = p.child4Old, + commandNo = r.commandNo, + commandYear = r.commandYear, + posNo = p.posMasterNoOld?.ToString(), + posNoAbb = p.child4ShortNameOld != null ? $"{p.child4ShortNameOld}" : + p.child3ShortNameOld != null ? $"{p.child3ShortNameOld}" : + p.child2ShortNameOld != null ? $"{p.child2ShortNameOld}" : + p.child1ShortNameOld != null ? $"{p.child1ShortNameOld}" : + p.rootShortNameOld != null ? $"{p.rootShortNameOld}" : "", + commandDateAffect = r.commandDateAffect, + commandDateSign = r.commandDateSign, + positionName = p.PositionOld, + commandCode = r.commandCode, + commandName = r.commandName, + remark = r.remark, + }).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, + }); + } + return Success(); + } + /// /// ส่งรายชื่อออกคำสั่ง C-PM-41 ///