diff --git a/BMA.EHR.Infrastructure/Storage/MinIOService.cs b/BMA.EHR.Infrastructure/Storage/MinIOService.cs index 31b9c6e2..30a4b036 100644 --- a/BMA.EHR.Infrastructure/Storage/MinIOService.cs +++ b/BMA.EHR.Infrastructure/Storage/MinIOService.cs @@ -3,6 +3,7 @@ using Amazon.S3.Model; using BMA.EHR.Domain.Models.Documents; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; diff --git a/BMA.EHR.Report.Service/Reports/ภาคผนวก59-เครื่องราชฯ1.trdp b/BMA.EHR.Report.Service/Reports/ภาคผนวก59-เครื่องราชฯ1.trdp index 9de4fd77..4ba8d6ef 100644 Binary files a/BMA.EHR.Report.Service/Reports/ภาคผนวก59-เครื่องราชฯ1.trdp and b/BMA.EHR.Report.Service/Reports/ภาคผนวก59-เครื่องราชฯ1.trdp differ diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs index 8567bae6..6ca44dbd 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs @@ -174,17 +174,19 @@ namespace BMA.EHR.Retirement.Service.Controllers /// /// สร้างประกาศเกษียณใหม่ /// - /// ประเภทUser(officer,employee)(ตัวใหญ่หรือเล็กก็ได้) - /// ปีงบประมาณ(ค.ศ.) + /// Id ประวัติรอบพ้นราชการ + /// ประเภทประกาศ + /// ประเภทUser(officer,employee)(ตัวใหญ่หรือเล็กก็ได้) + /// ปีงบประมาณ(ค.ศ.) /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน - [HttpGet("profile/{retire_history_id}/{option}/{type}/{year}")] - public async Task> CreateProfileRetirement(Guid retire_history_id, string option, string type, int year) + [HttpPost("profile")] + public async Task> CreateProfileRetirement([FromBody] PeriodRequest req) { - if (!type.Trim().ToUpper().Contains("EMPLOYEE") && !type.Trim().ToUpper().Contains("OFFICER")) + if (!req.Type.Trim().ToUpper().Contains("EMPLOYEE") && !req.Type.Trim().ToUpper().Contains("OFFICER")) return Error("ประเภทพ้นราชการไม่ถูกต้อง"); var round = 1; @@ -192,8 +194,8 @@ namespace BMA.EHR.Retirement.Service.Controllers .Include(x => x.RetirementPeriodHistorys) .Include(x => x.RetirementProfiles) .ThenInclude(x => x.Profile) - .Where(x => x.Year == year) - .Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper())) + .Where(x => x.Year == req.Year) + .Where(x => x.Type.Trim().ToUpper().Contains(req.Type.Trim().ToUpper())) .FirstOrDefaultAsync(); if (retire == null) { @@ -201,8 +203,8 @@ namespace BMA.EHR.Retirement.Service.Controllers { Round = round, TypeReport = null, - Type = type.Trim().ToUpper(), - Year = year, + Type = req.Type.Trim().ToUpper(), + Year = req.Year, CreatedUserId = FullName ?? "", CreatedFullName = UserId ?? "System Administrator", CreatedAt = DateTime.Now, @@ -212,10 +214,10 @@ namespace BMA.EHR.Retirement.Service.Controllers }; await _context.RetirementPeriods.AddAsync(retire); var profiles = await _context.Profiles.AsQueryable() - .Where(x => x.ProfileType.Trim().ToUpper().Contains(type.Trim().ToUpper())) + .Where(x => x.ProfileType.Trim().ToUpper().Contains(req.Type.Trim().ToUpper())) .ToListAsync(); - profiles = profiles.Where(x => x.BirthDate.CalculateRetireDate().Year == year).ToList(); + profiles = profiles.Where(x => x.BirthDate.CalculateRetireDate().Year == req.Year).ToList(); var order = 1; foreach (var profile in profiles) { @@ -240,8 +242,11 @@ namespace BMA.EHR.Retirement.Service.Controllers } else { + if (req.Option == null) + req.Option = "EDIT"; var file_name = DateTime.Now.ToString(); - await _documentService.GenerateJsonFile("xxx", "/retire", file_name); + var profile = Newtonsoft.Json.JsonConvert.SerializeObject(retire.RetirementProfiles); + await _documentService.GenerateJsonFile(profile, "/retire", file_name); var history = new RetirementPeriodHistory { RetirementPeriod = retire, @@ -262,11 +267,11 @@ namespace BMA.EHR.Retirement.Service.Controllers await _context.SaveChangesAsync(); retire.Round = retire.Round + 1; - retire.TypeReport = option.Trim().ToUpper(); + retire.TypeReport = req.Option.Trim().ToUpper(); retire.LastUpdateFullName = FullName ?? "System Administrator"; retire.LastUpdateUserId = UserId ?? ""; retire.LastUpdatedAt = DateTime.Now; - // retire_history_id + // RetireHistoryId ////ดึงไฟล์json // foreach (var retire_profile in retire.RetirementProfiles) // { @@ -383,10 +388,15 @@ namespace BMA.EHR.Retirement.Service.Controllers retire_profile.LastUpdateUserId = UserId ?? ""; retire_profile.LastUpdatedAt = DateTime.Now; } + var num = 1; + + var old_retire = retire.RetirementProfiles.OrderByDescending(x => x.Order).FirstOrDefault(); + if (old_retire != null) + num = old_retire.Order + 1; var data = new RetirementProfile { - Order = 1, + Order = num, Remove = "PENDING", RetirementPeriod = retire, Profile = profile, @@ -399,10 +409,10 @@ namespace BMA.EHR.Retirement.Service.Controllers }; _context.RetirementProfiles.Add(data); await _context.SaveChangesAsync(); - // if (retire.RetirementPeriodHistorys.Count() <= 1) - // { - // await GenOrderByYear(retire.Id); - // } + if (retire.RetirementPeriodHistorys.Count() == 0) + { + await GenOrderByYear(retire.Id); + } return Success(); } diff --git a/BMA.EHR.Retirement.Service/Requests/PeriodRequest.cs b/BMA.EHR.Retirement.Service/Requests/PeriodRequest.cs new file mode 100644 index 00000000..f6548769 --- /dev/null +++ b/BMA.EHR.Retirement.Service/Requests/PeriodRequest.cs @@ -0,0 +1,13 @@ +using BMA.EHR.Domain.Models.MetaData; +using Microsoft.EntityFrameworkCore; + +namespace BMA.EHR.Retirement.Service.Requests +{ + public class PeriodRequest + { + public Guid? RetireHistoryId { get; set; } + public string? Option { get; set; } + public string Type { get; set; } + public int Year { get; set; } + } +}