From aed9fb5051fbd5c2d2644a4efc2b189fe20cd4c9 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 28 Aug 2023 11:02:28 +0700 Subject: [PATCH 1/6] Add Report Designer Feature --- .../BMA.EHR.Report.Service.csproj | 3 + .../Controllers/ReportDesignerController.cs | 17 ++++ BMA.EHR.Report.Service/Program.cs | 33 +++++++- .../Properties/launchSettings.json | 82 +++++++++++-------- BMA.EHR.Report.Service/appsettings.json | 25 +++++- BMA.EHR.Report.Service/wwwroot/designer.html | 36 ++++++++ BMA.EHR.Solution.sln | 14 ++-- 7 files changed, 165 insertions(+), 45 deletions(-) create mode 100644 BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs create mode 100644 BMA.EHR.Report.Service/wwwroot/designer.html diff --git a/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj b/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj index 81eba980..06c0b58a 100644 --- a/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj +++ b/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj @@ -41,7 +41,10 @@ + + + diff --git a/BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs b/BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs new file mode 100644 index 00000000..1bbdf12a --- /dev/null +++ b/BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; +using Telerik.Reporting.Services; +using Telerik.WebReportDesigner.Services; +using Telerik.WebReportDesigner.Services.Controllers; + +namespace BMA.EHR.Report.Service.Controllers +{ + [Route("api/reportdesigner")] + public class ReportDesignerController : ReportDesignerControllerBase + { + public ReportDesignerController(IReportDesignerServiceConfiguration reportDesignerServiceConfiguration, + IReportServiceConfiguration reportServiceConfiguration) + : base(reportDesignerServiceConfiguration, reportServiceConfiguration) + { + } + } +} diff --git a/BMA.EHR.Report.Service/Program.cs b/BMA.EHR.Report.Service/Program.cs index 92f93f72..0ae0e309 100644 --- a/BMA.EHR.Report.Service/Program.cs +++ b/BMA.EHR.Report.Service/Program.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.IdentityModel.Logging; using Microsoft.IdentityModel.Tokens; using Serilog; @@ -15,6 +16,9 @@ using Serilog.Exceptions; using Serilog.Sinks.Elasticsearch; using System.Reflection; using System.Text; +using Telerik.Reporting.Cache.File; +using Telerik.Reporting.Services; +using Telerik.WebReportDesigner.Services; var builder = WebApplication.CreateBuilder(args); { @@ -92,6 +96,25 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.ConfigureOptions(); builder.Services.AddHealthChecks(); + + // For Telerik Report Designer + builder.Services.TryAddSingleton(sp => + new ReportServiceConfiguration + { + ReportingEngineConfiguration = ResolveSpecificReportingConfiguration(sp.GetService()), + HostAppId = "ReportingCoreApp", + Storage = new FileStorage(), + ReportSourceResolver = new TypeReportSourceResolver().AddFallbackResolver + (new UriReportSourceResolver(Path.Combine(sp.GetService().ContentRootPath, "Reports"))) + }); + builder.Services.TryAddSingleton(sp => new ReportDesignerServiceConfiguration + { + DefinitionStorage = new FileDefinitionStorage(Path.Combine(sp.GetService().ContentRootPath, "Reports"), new[] { "Resources", "Shared Data Sources" }), + ResourceStorage = new ResourceStorage(Path.Combine(sp.GetService().ContentRootPath, "Reports", "Resources")), + SharedDataSourceStorage = new FileSharedDataSourceStorage(Path.Combine(sp.GetService().ContentRootPath, "Reports", "Shared Data Sources")), + SettingsStorage = new FileSettingsStorage(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Telerik Reporting")) + }); + } var app = builder.Build(); @@ -113,7 +136,7 @@ var app = builder.Build(); app.MapHealthChecks("/health"); - + app.UseHttpsRedirection(); app.UseCors(); app.UseAuthentication(); @@ -131,6 +154,14 @@ var app = builder.Build(); app.Run(); } +static IConfiguration ResolveSpecificReportingConfiguration(IWebHostEnvironment environment) +{ + var reportingConfigFileName = Path.Combine(environment.ContentRootPath, "appsettings.json"); + return new ConfigurationBuilder() + .AddJsonFile(reportingConfigFileName, true) + .Build(); +} + void ConfigureLogs() { var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); diff --git a/BMA.EHR.Report.Service/Properties/launchSettings.json b/BMA.EHR.Report.Service/Properties/launchSettings.json index 985a5c8f..f41c4b5e 100644 --- a/BMA.EHR.Report.Service/Properties/launchSettings.json +++ b/BMA.EHR.Report.Service/Properties/launchSettings.json @@ -1,41 +1,51 @@ { - "profiles": { - "http": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "dotnetRunMessages": true, - "applicationUrl": "http://localhost:5156" + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5156" + }, + "https": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7164;http://localhost:5156" + }, + "report-designer": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "designer.html", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7164;http://localhost:5156" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "publishAllPorts": true, + "useSSL": true + } }, - "https": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "dotnetRunMessages": true, - "applicationUrl": "https://localhost:7164;http://localhost:5156" - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "Docker": { - "commandName": "Docker", - "launchBrowser": true, - "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", - "publishAllPorts": true, - "useSSL": true - } - }, "$schema": "https://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, diff --git a/BMA.EHR.Report.Service/appsettings.json b/BMA.EHR.Report.Service/appsettings.json index 254ef302..2d0fadb9 100644 --- a/BMA.EHR.Report.Service/appsettings.json +++ b/BMA.EHR.Report.Service/appsettings.json @@ -31,5 +31,28 @@ "SecretKey": "P@ssw0rd", "BucketName": "bma-recruit" }, - "Protocol": "HTTPS" + "Protocol": "HTTPS", + "telerikReporting": { + "privateFonts": [ + { + "fontFamily": "TH SarabunIT๙", + "path": "Fonts/THSarabunIT.ttf" + }, + { + "fontFamily": "TH SarabunIT๙", + "path": "Fonts/THSarabunITBold.ttf", + "fontStyle": "Bold" + }, + { + "fontFamily": "TH SarabunPSK", + "path": "Fonts/THSarabunNew.ttf", + + }, + { + "fontFamily": "TH SarabunPSK", + "path": "Fonts/THSarabunNewBold.ttf", + "fontStyle": "Bold" + } + ] + } } \ No newline at end of file diff --git a/BMA.EHR.Report.Service/wwwroot/designer.html b/BMA.EHR.Report.Service/wwwroot/designer.html new file mode 100644 index 00000000..d32e628f --- /dev/null +++ b/BMA.EHR.Report.Service/wwwroot/designer.html @@ -0,0 +1,36 @@ + + + + Telerik Web Report Designer + + + + + + + + +
+ loading... +
+ + + + + + + + + + + \ No newline at end of file diff --git a/BMA.EHR.Solution.sln b/BMA.EHR.Solution.sln index 72be7ede..003c2a21 100644 --- a/BMA.EHR.Solution.sln +++ b/BMA.EHR.Solution.sln @@ -19,14 +19,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BMA.EHR.Placement.Service", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BMA.EHR.OrganizationEmployee.Service", "BMA.EHR.OrganizationEmployee.Service\BMA.EHR.OrganizationEmployee.Service.csproj", "{A54AA069-8B0E-4784-953B-5DA9F9C8285E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BMA.EHR.Report.Service", "BMA.EHR.Report.Service\BMA.EHR.Report.Service.csproj", "{AC4B2602-C543-4165-85D7-F6F92F553D80}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BMA.EHR.Command.Service", "BMA.EHR.Command.Service\BMA.EHR.Command.Service.csproj", "{E4E905EE-61DF-4451-B063-5C86BC7574CE}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BMA.EHR.Insignia.Service", "BMA.EHR.Insignia.Service\BMA.EHR.Insignia.Service.csproj", "{04B37ACD-65CF-44ED-BC40-B5E7A71C374B}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BMA.EHR.Retirement.Service", "BMA.EHR.Retirement.Service\BMA.EHR.Retirement.Service.csproj", "{3FFE378C-387F-42EA-96E2-68E63BB295F9}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BMA.EHR.Report.Service", "BMA.EHR.Report.Service\BMA.EHR.Report.Service.csproj", "{26FE7B1C-771B-4940-9F40-326A7AD53F1C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -57,10 +57,6 @@ Global {A54AA069-8B0E-4784-953B-5DA9F9C8285E}.Debug|Any CPU.Build.0 = Debug|Any CPU {A54AA069-8B0E-4784-953B-5DA9F9C8285E}.Release|Any CPU.ActiveCfg = Release|Any CPU {A54AA069-8B0E-4784-953B-5DA9F9C8285E}.Release|Any CPU.Build.0 = Release|Any CPU - {AC4B2602-C543-4165-85D7-F6F92F553D80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AC4B2602-C543-4165-85D7-F6F92F553D80}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AC4B2602-C543-4165-85D7-F6F92F553D80}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AC4B2602-C543-4165-85D7-F6F92F553D80}.Release|Any CPU.Build.0 = Release|Any CPU {E4E905EE-61DF-4451-B063-5C86BC7574CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E4E905EE-61DF-4451-B063-5C86BC7574CE}.Debug|Any CPU.Build.0 = Debug|Any CPU {E4E905EE-61DF-4451-B063-5C86BC7574CE}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -73,6 +69,10 @@ Global {3FFE378C-387F-42EA-96E2-68E63BB295F9}.Debug|Any CPU.Build.0 = Debug|Any CPU {3FFE378C-387F-42EA-96E2-68E63BB295F9}.Release|Any CPU.ActiveCfg = Release|Any CPU {3FFE378C-387F-42EA-96E2-68E63BB295F9}.Release|Any CPU.Build.0 = Release|Any CPU + {26FE7B1C-771B-4940-9F40-326A7AD53F1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {26FE7B1C-771B-4940-9F40-326A7AD53F1C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {26FE7B1C-771B-4940-9F40-326A7AD53F1C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {26FE7B1C-771B-4940-9F40-326A7AD53F1C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -85,10 +85,10 @@ Global {FA618F0C-1AF5-49AB-AE13-C020B403B64F} = {F3C2F68F-8DC8-45A3-825B-24F17867D380} {81610EF7-AF80-44D8-9263-925C821CF45F} = {FA618F0C-1AF5-49AB-AE13-C020B403B64F} {A54AA069-8B0E-4784-953B-5DA9F9C8285E} = {FA618F0C-1AF5-49AB-AE13-C020B403B64F} - {AC4B2602-C543-4165-85D7-F6F92F553D80} = {FA618F0C-1AF5-49AB-AE13-C020B403B64F} {E4E905EE-61DF-4451-B063-5C86BC7574CE} = {FA618F0C-1AF5-49AB-AE13-C020B403B64F} {04B37ACD-65CF-44ED-BC40-B5E7A71C374B} = {FA618F0C-1AF5-49AB-AE13-C020B403B64F} {3FFE378C-387F-42EA-96E2-68E63BB295F9} = {FA618F0C-1AF5-49AB-AE13-C020B403B64F} + {26FE7B1C-771B-4940-9F40-326A7AD53F1C} = {FA618F0C-1AF5-49AB-AE13-C020B403B64F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3111A492-1818-4438-B718-75199D8E779A} From 6253d8d2ab36c85a67d21a8305e8fc1404d34cee Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 28 Aug 2023 16:18:35 +0700 Subject: [PATCH 2/6] Get Receiver for Command C-PM-01, C-PM-02 --- .../Commands/CommandRepository.cs | 116 +++++++++++++++--- .../Repositories/GenericRepository.cs | 27 +++- 2 files changed, 119 insertions(+), 24 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 26f85397..fdc8be31 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -71,10 +71,11 @@ namespace BMA.EHR.Application.Repositories.Commands switch (command.CommandType.CommandCode.Trim().ToUpper()) { case "C-PM-01": - case "C-PM-02": - case "C-PM-03": result = await GetReceiver01Async(command); break; + case "C-PM-02": + result = await GetReceiver02Async(command); + break; default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); } @@ -82,9 +83,9 @@ namespace BMA.EHR.Application.Repositories.Commands } /// - /// C-PM-01 + /// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้ /// - /// + /// object ของรายการคำสั่ง /// private async Task> GetReceiver01Async(Command command) { @@ -97,13 +98,15 @@ namespace BMA.EHR.Application.Repositories.Commands var otherCommandReceivers = await _dbContext.Set() .Include(x => x.Command) .ThenInclude(x => x.CommandType) - .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper().StartsWith("C-PM")) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper().StartsWith("C-PM-01")) .Where(x => x.Command.Id != command.Id) .Select(x => x.CitizenId) .ToListAsync(); // 2. Query var appointPeople = await _dbContext.Set() + .Include(x => x.Placement) + .ThenInclude(x => x.PlacementType) .Include(x => x.Prefix) .Include(x => x.OrganizationPosition) .ThenInclude(x => x!.Organization) @@ -111,6 +114,7 @@ namespace BMA.EHR.Application.Repositories.Commands .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") .Where(x => x.Draft! == true) + .Where(x => x.Placement!.PlacementType!.Name == "สอบแข่งขัน") .OrderBy(x => x.ExamNumber) .ToListAsync(); @@ -118,19 +122,20 @@ namespace BMA.EHR.Application.Repositories.Commands var seq = 1; foreach (var item in appointPeople) { - - var receiver = new CommandReceiver + if (!(await CheckIsActiveOfficer(item.CitizenId!))) { - Sequence = seq, - CitizenId = item.CitizenId!, - Prefix = item.Prefix!.Name, - FirstName = item.Firstname!, - LastName = item.Lastname!, - RefPlacementProfileId = item.Id - }; - seq++; - - result.Add(receiver); + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + result.Add(receiver); + } } return result; @@ -141,6 +146,72 @@ namespace BMA.EHR.Application.Repositories.Commands } } + /// + /// C-PM-02 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver02Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-02") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Placement) + .ThenInclude(x => x.PlacementType) + .Include(x => x.Prefix) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.Organization) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) + .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") + .Where(x => x.Draft! == true) + .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") + .OrderBy(x => x.ExamNumber) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + if (!(await CheckIsActiveOfficer(item.CitizenId!))) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + } + + return result; + } + catch + { + throw; + } + } + + #endregion #region " Execute and Deploy " @@ -151,15 +222,20 @@ namespace BMA.EHR.Application.Repositories.Commands { case "C-PM-01": case "C-PM-02": - case "C-PM-03": - await ExecuteCommand01Async(command); + await ExecuteCommand01_02Async(command); break; default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); } } - private async Task ExecuteCommand01Async(Command command) + /// + /// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้, + /// C-PM-02 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand01_02Async(Command command) { try { diff --git a/BMA.EHR.Application/Repositories/GenericRepository.cs b/BMA.EHR.Application/Repositories/GenericRepository.cs index 29354dc1..6ba9c059 100644 --- a/BMA.EHR.Application/Repositories/GenericRepository.cs +++ b/BMA.EHR.Application/Repositories/GenericRepository.cs @@ -1,5 +1,7 @@ -using BMA.EHR.Application.Common.Interfaces; +using Amazon.S3.Model.Internal.MarshallTransformations; +using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Domain.Models.Base; +using BMA.EHR.Domain.Models.HR; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using System.Security.Claims; @@ -13,7 +15,7 @@ namespace BMA.EHR.Application.Repositories private readonly IApplicationDBContext _dbContext; private readonly DbSet _dbSet; private readonly IHttpContextAccessor _httpContextAccessor; - + #endregion #region " Constructor and Destructor " @@ -24,7 +26,7 @@ namespace BMA.EHR.Application.Repositories _dbContext = dbContext; _dbSet = _dbContext.Set(); _httpContextAccessor = httpContextAccessor; - + } #endregion @@ -35,12 +37,29 @@ namespace BMA.EHR.Application.Repositories protected string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; - protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1"); + protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1"); #endregion #region " Methods " + public async Task CheckIsActiveOfficer(string citizenId) + { + try + { + var pf = await _dbContext.Set() + .Where(x => x.CitizenId == citizenId) + .Where(x => x.ProfileType.ToLower().Trim() == "officer" && x.IsActive && !x.IsLeave) + .FirstOrDefaultAsync(); + + return pf != null; + } + catch + { + throw; + } + } + public virtual async Task> GetAllAsync() { return await _dbSet.ToListAsync(); From 9b3efd898153ebbc49ab104709c3900b988156a9 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 28 Aug 2023 16:44:31 +0700 Subject: [PATCH 3/6] Get command Receiver For C-PM-03 , C-PM-04 --- .../Commands/CommandRepository.cs | 137 ++++++++++++++++++ .../Repositories/GenericRepository.cs | 19 ++- 2 files changed, 155 insertions(+), 1 deletion(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index fdc8be31..b20e9dc4 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -76,6 +76,12 @@ namespace BMA.EHR.Application.Repositories.Commands case "C-PM-02": result = await GetReceiver02Async(command); break; + case "C-PM-03": + result = await GetReceiver03Async(command); + break; + case "C-PM-04": + result = await GetReceiver04Async(command); + break; default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); } @@ -211,6 +217,137 @@ namespace BMA.EHR.Application.Repositories.Commands } } + /// + /// C-PM-03 - คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver03Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-03") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Placement) + .ThenInclude(x => x.PlacementType) + .Include(x => x.Prefix) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.Organization) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) + .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") + .Where(x => x.Draft! == true) + // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") + .OrderBy(x => x.ExamNumber) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var profile_oc = await GetProfileOrganizationAsync(item.CitizenId!); + if ((await CheckIsActiveOfficerAsync(item.CitizenId!)) && item.OrganizationPosition!.Organization!.Id == profile_oc) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-04 - คำสั่งย้าย : สำหรับข้าราชการ กทม. เดิม + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver04Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-03") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Placement) + .ThenInclude(x => x.PlacementType) + .Include(x => x.Prefix) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.Organization) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) + .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") + .Where(x => x.Draft! == true) + // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") + .OrderBy(x => x.ExamNumber) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var profile_oc = await GetProfileOrganizationAsync(item.CitizenId!); + if ((await CheckIsActiveOfficerAsync(item.CitizenId!)) && item.OrganizationPosition!.Organization!.Id != profile_oc) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + } + + return result; + } + catch + { + throw; + } + } #endregion diff --git a/BMA.EHR.Application/Repositories/GenericRepository.cs b/BMA.EHR.Application/Repositories/GenericRepository.cs index 6ba9c059..44503ad2 100644 --- a/BMA.EHR.Application/Repositories/GenericRepository.cs +++ b/BMA.EHR.Application/Repositories/GenericRepository.cs @@ -43,7 +43,24 @@ namespace BMA.EHR.Application.Repositories #region " Methods " - public async Task CheckIsActiveOfficer(string citizenId) + public async Task GetProfileOrganizationAsync(string citizenId) + { + try + { + var pf = await _dbContext.Set() + .Where(x => x.CitizenId == citizenId) + .Where(x => x.ProfileType.ToLower().Trim() == "officer" && x.IsActive && !x.IsLeave) + .FirstOrDefaultAsync(); + + return pf == null || pf.Oc == null ? Guid.Empty : pf.OcId!.Value; + } + catch + { + throw; + } + } + + public async Task CheckIsActiveOfficerAsync(string citizenId) { try { From ec3395d97065bd63099bf4354352c27a3a0aff0b Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 29 Aug 2023 08:40:16 +0700 Subject: [PATCH 4/6] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9B?= =?UTF-8?q?=E0=B8=B1=E0=B8=8D=E0=B8=AB=E0=B8=B2=20swagger=20=E0=B8=AA?= =?UTF-8?q?=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87=20page=20Error=20=E0=B9=80?= =?UTF-8?q?=E0=B8=A1=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B9=83=E0=B8=8A=E0=B9=89?= =?UTF-8?q?=E0=B8=87=E0=B8=B2=E0=B8=99=20WebREportDesigner=20****=20?= =?UTF-8?q?=E0=B8=A2=E0=B8=B1=E0=B8=87=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B9=84?= =?UTF-8?q?=E0=B8=94=E0=B9=89=20=E0=B9=80=E0=B8=A5=E0=B8=A2=E0=B9=80?= =?UTF-8?q?=E0=B8=AD=E0=B8=B2=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=88=E0=B8=B2?= =?UTF-8?q?=E0=B8=81=E0=B8=A3=E0=B8=B0=E0=B8=9A=E0=B8=9A=E0=B9=84=E0=B8=9B?= =?UTF-8?q?=E0=B8=81=E0=B9=88=E0=B8=AD=E0=B8=99=20*****?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/CommandRepository.cs | 4 +-- .../BMA.EHR.Report.Service.csproj | 10 +++--- .../ConfigureSwaggerOptions.cs | 9 ++++-- .../Controllers/InsigniaReportController.cs | 8 ----- .../Controllers/ReportDesignerController.cs | 17 ---------- BMA.EHR.Report.Service/OpenApiIgnoreFilter.cs | 31 +++++++++++++++++++ BMA.EHR.Report.Service/Program.cs | 28 ++++------------- 7 files changed, 52 insertions(+), 55 deletions(-) delete mode 100644 BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs create mode 100644 BMA.EHR.Report.Service/OpenApiIgnoreFilter.cs diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index b20e9dc4..69c99f0c 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -128,7 +128,7 @@ namespace BMA.EHR.Application.Repositories.Commands var seq = 1; foreach (var item in appointPeople) { - if (!(await CheckIsActiveOfficer(item.CitizenId!))) + if (!(await CheckIsActiveOfficerAsync(item.CitizenId!))) { var receiver = new CommandReceiver { @@ -192,7 +192,7 @@ namespace BMA.EHR.Application.Repositories.Commands var seq = 1; foreach (var item in appointPeople) { - if (!(await CheckIsActiveOfficer(item.CitizenId!))) + if (!(await CheckIsActiveOfficerAsync(item.CitizenId!))) { var receiver = new CommandReceiver { diff --git a/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj b/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj index 06c0b58a..0d1ad60c 100644 --- a/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj +++ b/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj @@ -11,6 +11,10 @@ BMA.EHR.Report.Service + + + + @@ -29,7 +33,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive
- + @@ -41,10 +45,8 @@ - - - + diff --git a/BMA.EHR.Report.Service/ConfigureSwaggerOptions.cs b/BMA.EHR.Report.Service/ConfigureSwaggerOptions.cs index 18f4a719..17919338 100644 --- a/BMA.EHR.Report.Service/ConfigureSwaggerOptions.cs +++ b/BMA.EHR.Report.Service/ConfigureSwaggerOptions.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.Extensions.Options; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; @@ -19,6 +20,9 @@ namespace BMA.EHR.Report.Service public void Configure(SwaggerGenOptions options) { // add swagger document for every API version discovered + + + foreach (var description in _provider.ApiVersionDescriptions) { options.EnableAnnotations(); @@ -26,8 +30,9 @@ namespace BMA.EHR.Report.Service options.SwaggerDoc( description.GroupName, CreateVersionInfo(description)); - } + + } options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { In = ParameterLocation.Header, diff --git a/BMA.EHR.Report.Service/Controllers/InsigniaReportController.cs b/BMA.EHR.Report.Service/Controllers/InsigniaReportController.cs index c6136721..dd9b8c83 100644 --- a/BMA.EHR.Report.Service/Controllers/InsigniaReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/InsigniaReportController.cs @@ -1,15 +1,7 @@ using BMA.EHR.Domain.Common; -using BMA.EHR.Domain.Extensions; -using BMA.EHR.Domain.Shared; -using BMA.EHR.Application.Repositories.Reports; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; using Swashbuckle.AspNetCore.Annotations; -using DocumentFormat.OpenXml.Drawing; -using Telerik.Reporting; -using Telerik.Reporting.Processing; -using System.IO; namespace BMA.EHR.Report.Service.Controllers { diff --git a/BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs b/BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs deleted file mode 100644 index 1bbdf12a..00000000 --- a/BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Telerik.Reporting.Services; -using Telerik.WebReportDesigner.Services; -using Telerik.WebReportDesigner.Services.Controllers; - -namespace BMA.EHR.Report.Service.Controllers -{ - [Route("api/reportdesigner")] - public class ReportDesignerController : ReportDesignerControllerBase - { - public ReportDesignerController(IReportDesignerServiceConfiguration reportDesignerServiceConfiguration, - IReportServiceConfiguration reportServiceConfiguration) - : base(reportDesignerServiceConfiguration, reportServiceConfiguration) - { - } - } -} diff --git a/BMA.EHR.Report.Service/OpenApiIgnoreFilter.cs b/BMA.EHR.Report.Service/OpenApiIgnoreFilter.cs new file mode 100644 index 00000000..6a7aa28d --- /dev/null +++ b/BMA.EHR.Report.Service/OpenApiIgnoreFilter.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.OpenApi.Models; +using NSwag.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using System.Reflection; + +namespace BMA.EHR.Report.Service +{ + public class OpenApiIgnoreFilter: IDocumentFilter + { + public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) + { + foreach (var apiDescription in context.ApiDescriptions) + { + var actionDescriptor = apiDescription.ActionDescriptor as ControllerActionDescriptor; + if (actionDescriptor != null) + { + var ignoreAttribute = actionDescriptor.MethodInfo.GetCustomAttribute(); + if (ignoreAttribute != null) + { + var routeKey = "/" + apiDescription.RelativePath.TrimEnd('/'); + if (swaggerDoc.Paths.ContainsKey(routeKey)) + { + swaggerDoc.Paths.Remove(routeKey); + } + } + } + } + } + } +} diff --git a/BMA.EHR.Report.Service/Program.cs b/BMA.EHR.Report.Service/Program.cs index 0ae0e309..b29da486 100644 --- a/BMA.EHR.Report.Service/Program.cs +++ b/BMA.EHR.Report.Service/Program.cs @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.IdentityModel.Logging; using Microsoft.IdentityModel.Tokens; using Serilog; @@ -16,9 +15,6 @@ using Serilog.Exceptions; using Serilog.Sinks.Elasticsearch; using System.Reflection; using System.Text; -using Telerik.Reporting.Cache.File; -using Telerik.Reporting.Services; -using Telerik.WebReportDesigner.Services; var builder = WebApplication.CreateBuilder(args); { @@ -92,28 +88,16 @@ var builder = WebApplication.CreateBuilder(args); }) .AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); - builder.Services.AddSwaggerGen(); + builder.Services.AddSwaggerGen(c => + { + c.IgnoreObsoleteActions(); + c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); + }); builder.Services.ConfigureOptions(); builder.Services.AddHealthChecks(); - // For Telerik Report Designer - builder.Services.TryAddSingleton(sp => - new ReportServiceConfiguration - { - ReportingEngineConfiguration = ResolveSpecificReportingConfiguration(sp.GetService()), - HostAppId = "ReportingCoreApp", - Storage = new FileStorage(), - ReportSourceResolver = new TypeReportSourceResolver().AddFallbackResolver - (new UriReportSourceResolver(Path.Combine(sp.GetService().ContentRootPath, "Reports"))) - }); - builder.Services.TryAddSingleton(sp => new ReportDesignerServiceConfiguration - { - DefinitionStorage = new FileDefinitionStorage(Path.Combine(sp.GetService().ContentRootPath, "Reports"), new[] { "Resources", "Shared Data Sources" }), - ResourceStorage = new ResourceStorage(Path.Combine(sp.GetService().ContentRootPath, "Reports", "Resources")), - SharedDataSourceStorage = new FileSharedDataSourceStorage(Path.Combine(sp.GetService().ContentRootPath, "Reports", "Shared Data Sources")), - SettingsStorage = new FileSettingsStorage(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Telerik Reporting")) - }); + } From 7cd2f7d82fb508636149cd9f4d4756a2525f789f Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Wed, 30 Aug 2023 12:05:34 +0700 Subject: [PATCH 5/6] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3?= =?UTF-8?q?=E0=B8=94=E0=B8=B6=E0=B8=87=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=8A?= =?UTF-8?q?=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B8=A3?= =?UTF-8?q?=E0=B8=B1=E0=B8=9A=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88?= =?UTF-8?q?=E0=B8=87=20=E0=B8=82=E0=B8=B2=E0=B8=94=2010-11-12=20=E0=B8=A3?= =?UTF-8?q?=E0=B8=AD=E0=B8=96=E0=B8=B2=E0=B8=A1=E0=B8=AD=E0=B8=B8=E0=B9=8B?= =?UTF-8?q?=E0=B8=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/CommandRepository.cs | 797 +++++++++++++++++- 1 file changed, 796 insertions(+), 1 deletion(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 69c99f0c..fa489c66 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -9,6 +9,7 @@ using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.Notifications; using BMA.EHR.Domain.Models.Organizations; using BMA.EHR.Domain.Models.Placement; +using BMA.EHR.Domain.Models.Retirement; using BMA.EHR.Domain.Shared; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; @@ -82,6 +83,45 @@ namespace BMA.EHR.Application.Repositories.Commands case "C-PM-04": result = await GetReceiver04Async(command); break; + case "C-PM-05": + result = await GetReceiver05Async(command); + break; + case "C-PM-06": + result = await GetReceiver06Async(command); + break; + case "C-PM-07": + result = await GetReceiver07Async(command); + break; + case "C-PM-08": + result = await GetReceiver08Async(command); + break; + case "C-PM-09": + result = await GetReceiver09Async(command); + break; + case "C-PM-13": + result = await GetReceiver13Async(command); + break; + case "C-PM-14": + result = await GetReceiver14Async(command); + break; + case "C-PM-15": + result = await GetReceiver15Async(command); + break; + case "C-PM-16": + result = await GetReceiver16Async(command); + break; + case "C-PM-17": + result = await GetReceiver17Async(command); + break; + case "C-PM-18": + result = await GetReceiver18Async(command); + break; + case "C-PM-19": + result = await GetReceiver19Async(command); + break; + case "C-PM-20": + result = await GetReceiver20Async(command); + break; default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); } @@ -299,7 +339,7 @@ namespace BMA.EHR.Application.Repositories.Commands var otherCommandReceivers = await _dbContext.Set() .Include(x => x.Command) .ThenInclude(x => x.CommandType) - .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-03") + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-04") .Where(x => x.Command.Id != command.Id) .Select(x => x.CitizenId) .ToListAsync(); @@ -349,6 +389,761 @@ namespace BMA.EHR.Application.Repositories.Commands } } + /// + /// C-PM-05 - คำสั่งแต่งตั้ง + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver05Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-05") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.CommandType) + .Include(x => x.Prefix) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.Organization) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .Where(x => x.CommandType!.Id == command.CommandType!.Id) + .OrderBy(x => x.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-06 - คำสั่งเลื่อน + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver06Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-06") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.CommandType) + .Include(x => x.Prefix) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.Organization) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .Where(x => x.CommandType!.Id == command.CommandType!.Id) + .OrderBy(x => x.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-07 - คำสั่งย้าย + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver07Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-07") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Prefix) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.Organization) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .OrderBy(x => x.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-08 - คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver08Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-08") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.CommandType) + .Include(x => x.Prefix) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.Organization) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .Where(x => x.CommandType!.Id == command.CommandType!.Id) + .OrderBy(x => x.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-09 - คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver09Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-09") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.CommandType) + .Include(x => x.Prefix) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.Organization) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .Where(x => x.CommandType!.Id == command.CommandType!.Id) + .OrderBy(x => x.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-13 - คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver13Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-13") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Prefix) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .OrderBy(x => x.Profile!.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.Profile!.CitizenId!, + Prefix = item.Profile!.Prefix!.Name, + FirstName = item.Profile!.FirstName!, + LastName = item.Profile!.LastName!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-14 - คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver14Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-14") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Prefix) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.Organization) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .OrderBy(x => x.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.CitizenId!, + Prefix = item.Prefix!.Name, + FirstName = item.Firstname!, + LastName = item.Lastname!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-15 - คำสั่งให้ช่วยราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver15Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-15") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Prefix) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .OrderBy(x => x.Profile!.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.Profile!.CitizenId!, + Prefix = item.Profile!.Prefix!.Name, + FirstName = item.Profile!.FirstName!, + LastName = item.Profile!.LastName!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-16 - คำสั่งส่งตัวกลับ + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver16Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-16") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Prefix) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .OrderBy(x => x.Profile!.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.Profile!.CitizenId!, + Prefix = item.Profile!.Prefix!.Name, + FirstName = item.Profile!.FirstName!, + LastName = item.Profile!.LastName!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-17 - คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver17Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-17") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Prefix) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .OrderBy(x => x.Profile!.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.Profile!.CitizenId!, + Prefix = item.Profile!.Prefix!.Name, + FirstName = item.Profile!.FirstName!, + LastName = item.Profile!.LastName!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-18 - คำสั่งให้ออกจากราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver18Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-18") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Prefix) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .OrderBy(x => x.Profile!.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.Profile!.CitizenId!, + Prefix = item.Profile!.Prefix!.Name, + FirstName = item.Profile!.FirstName!, + LastName = item.Profile!.LastName!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-19 - คำสั่งปลดออกจากราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver19Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-19") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Prefix) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .OrderBy(x => x.Profile!.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.Profile!.CitizenId!, + Prefix = item.Profile!.Prefix!.Name, + FirstName = item.Profile!.FirstName!, + LastName = item.Profile!.LastName!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + + /// + /// C-PM-20 - คำสั่งไล่ออกจากราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task> GetReceiver20Async(Command command) + { + try + { + var result = new List(); + // TODO : ต้องมา list คนตามประเภทอีกครั้งนึง + + // 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน + var otherCommandReceivers = await _dbContext.Set() + .Include(x => x.Command) + .ThenInclude(x => x.CommandType) + .Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-20") + .Where(x => x.Command.Id != command.Id) + .Select(x => x.CitizenId) + .ToListAsync(); + + // 2. Query + var appointPeople = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Prefix) + //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!)) + .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .OrderBy(x => x.Profile!.CitizenId) + .ToListAsync(); + + // 3. Create new Record + var seq = 1; + foreach (var item in appointPeople) + { + var receiver = new CommandReceiver + { + Sequence = seq, + CitizenId = item.Profile!.CitizenId!, + Prefix = item.Profile!.Prefix!.Name, + FirstName = item.Profile!.FirstName!, + LastName = item.Profile!.LastName!, + RefPlacementProfileId = item.Id + }; + seq++; + + result.Add(receiver); + } + + return result; + } + catch + { + throw; + } + } + #endregion #region " Execute and Deploy " From 89c7b6e239b4cbaa579d0e3a7075666f43673287 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 31 Aug 2023 10:26:53 +0700 Subject: [PATCH 6/6] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=E0=B8=9A=E0=B8=B1=E0=B9=89=E0=B8=81=20api=20=E0=B8=84?= =?UTF-8?q?=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=20=E0=B9=80?= =?UTF-8?q?=E0=B8=A5=E0=B8=B7=E0=B8=AD=E0=B8=81=E0=B8=A3=E0=B8=B2=E0=B8=A2?= =?UTF-8?q?=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B9=80=E0=B8=9E=E0=B8=B7?= =?UTF-8?q?=E0=B9=88=E0=B8=AD=E0=B8=97=E0=B8=B3=E0=B8=84=E0=B8=B3=E0=B8=AA?= =?UTF-8?q?=E0=B8=B1=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/CommandRepository.cs | 11 ++-- .../Controllers/OrderController.cs | 57 ++++++++++++++----- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index fa489c66..f0a39509 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -289,7 +289,6 @@ namespace BMA.EHR.Application.Repositories.Commands .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") .Where(x => x.Draft! == true) - // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") .OrderBy(x => x.ExamNumber) .ToListAsync(); @@ -298,7 +297,7 @@ namespace BMA.EHR.Application.Repositories.Commands foreach (var item in appointPeople) { var profile_oc = await GetProfileOrganizationAsync(item.CitizenId!); - if ((await CheckIsActiveOfficerAsync(item.CitizenId!)) && item.OrganizationPosition!.Organization!.Id == profile_oc) + if (await CheckIsActiveOfficerAsync(item.CitizenId!)) { var receiver = new CommandReceiver { @@ -351,11 +350,9 @@ namespace BMA.EHR.Application.Repositories.Commands .Include(x => x.Prefix) .Include(x => x.OrganizationPosition) .ThenInclude(x => x!.Organization) - //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") .Where(x => x.Draft! == true) - // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") .OrderBy(x => x.ExamNumber) .ToListAsync(); @@ -364,7 +361,7 @@ namespace BMA.EHR.Application.Repositories.Commands foreach (var item in appointPeople) { var profile_oc = await GetProfileOrganizationAsync(item.CitizenId!); - if ((await CheckIsActiveOfficerAsync(item.CitizenId!)) && item.OrganizationPosition!.Organization!.Id != profile_oc) + if (await CheckIsActiveOfficerAsync(item.CitizenId!)) { var receiver = new CommandReceiver { @@ -531,13 +528,15 @@ namespace BMA.EHR.Application.Repositories.Commands .ToListAsync(); // 2. Query - var appointPeople = await _dbContext.Set() + var appointPeople = await _dbContext.Set() + .Include(x => x.CommandType) .Include(x => x.Prefix) .Include(x => x.OrganizationPosition) .ThenInclude(x => x!.Organization) //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) .Where(x => x.Status.Trim().ToUpper() == "REPORT") + .Where(x => x.CommandType!.Id == command.CommandType!.Id) .OrderBy(x => x.CitizenId) .ToListAsync(); diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 7388b71a..88b79589 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -2484,6 +2484,10 @@ namespace BMA.EHR.Command.Service.Controllers { try { + var command = await _repository.GetByIdAsync(orderId); + if (command == null) + throw new Exception(GlobalMessages.CommandNotFound); + // TODO : หาค่า Education มาแสดง var existed = await _repository.GetReceiverByCommmandIdAsync(orderId); @@ -2500,13 +2504,25 @@ namespace BMA.EHR.Command.Service.Controllers Education = "" // ยังหาไม่เจอว่าอยุ่ field ไหน }).ToList(); - foreach (var r in receivers) + // ให้ Update Salary เฉพาะของ Command 01-04 + switch (command.CommandType.CommandCode.ToUpper()) { - var salary = await _repository.GetPlacementSalaryAsync(r.RefRecordId); - - r.SalaryAmount = salary.SalaryAmount; - r.PositionSalaryAmount = salary.PositionSalaryAmount; - r.MonthSalaryAmount = salary.MonthSalaryAmount; + case "C-PM-01": + case "C-PM-02": + case "C-PM-03": + case "c-PM-04": + { + foreach (var r in receivers) + { + var salary = await _repository.GetPlacementSalaryAsync(r.RefRecordId); + r.SalaryAmount = salary.SalaryAmount; + r.PositionSalaryAmount = salary.PositionSalaryAmount; + r.MonthSalaryAmount = salary.MonthSalaryAmount; + } + } + break; + default: + break; } return Success(receivers); @@ -2534,8 +2550,12 @@ namespace BMA.EHR.Command.Service.Controllers { try { + var command = await _repository.GetByIdAsync(orderId); + if (command == null) + throw new Exception(GlobalMessages.CommandNotFound); + var receivers = (await _repository.GetReceiverByCommmandIdAsync(orderId)) - .OrderBy(x => x.Sequence) + .OrderBy(x => x.Sequence) .Select(r => new CommandReceiverResponse { RefRecordId = r.RefPlacementProfileId!.Value, @@ -2547,13 +2567,24 @@ namespace BMA.EHR.Command.Service.Controllers Education = "" // ยังหาไม่เจอว่าอยุ่ field ไหน }).ToList(); - foreach (var r in receivers) + // ให้ Update Salary เฉพาะของ Command 01-04 + switch (command.CommandType.CommandCode.ToUpper()) { - var salary = await _repository.GetPlacementSalaryAsync(r.RefRecordId); - - r.SalaryAmount = salary.SalaryAmount; - r.PositionSalaryAmount = salary.PositionSalaryAmount; - r.MonthSalaryAmount = salary.MonthSalaryAmount; + case "C-PM-01": + case "C-PM-02": + case "C-PM-03": + case "c-PM-04": + { + foreach (var r in receivers) + { + var salary = await _repository.GetPlacementSalaryAsync(r.RefRecordId); + r.SalaryAmount = salary.SalaryAmount; + r.PositionSalaryAmount = salary.PositionSalaryAmount; + r.MonthSalaryAmount = salary.MonthSalaryAmount; + } + break; + } + default: break; } return Success(receivers);