From f83a59733f3f6d2c6d3b877860385cba317fb0e2 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 3 Aug 2023 23:02:59 +0700 Subject: [PATCH] add nuget aws s3 --- .../BMA.EHR.Infrastructure.csproj | 1 + .../Storage/MinIOService.cs | 19 +- .../BMA.EHR.Retirement.Service.csproj | 1 + .../Controllers/RetirementController.cs | 163 +++++++++++------- .../tmp/20230803T211254.json | 1 + 5 files changed, 115 insertions(+), 70 deletions(-) create mode 100644 BMA.EHR.Retirement.Service/tmp/20230803T211254.json diff --git a/BMA.EHR.Infrastructure/BMA.EHR.Infrastructure.csproj b/BMA.EHR.Infrastructure/BMA.EHR.Infrastructure.csproj index 5fa3ecca..548ca640 100644 --- a/BMA.EHR.Infrastructure/BMA.EHR.Infrastructure.csproj +++ b/BMA.EHR.Infrastructure/BMA.EHR.Infrastructure.csproj @@ -7,6 +7,7 @@ + diff --git a/BMA.EHR.Infrastructure/Storage/MinIOService.cs b/BMA.EHR.Infrastructure/Storage/MinIOService.cs index 51dc5499..84a81e48 100644 --- a/BMA.EHR.Infrastructure/Storage/MinIOService.cs +++ b/BMA.EHR.Infrastructure/Storage/MinIOService.cs @@ -268,6 +268,11 @@ namespace BMA.EHR.Application.Repositories var fileExt = Path.GetExtension(fileName); var fileType = MimeTypeMap.GetMimeType(fileExt); var file_name = Path.GetFileName(fileName); + Console.WriteLine($"{_bucketName}{subFolder}"); + Console.WriteLine(fileName); + Console.WriteLine(file_name); + Console.WriteLine(filestream); + Console.WriteLine(fileType); var request = new PutObjectRequest { @@ -288,17 +293,15 @@ namespace BMA.EHR.Application.Repositories public async Task GenerateJsonFile(string json, string path, string fileName) { - var tmpFile = ""; + var tmpDir = Path.Combine("tmp"); + if (!Directory.Exists(tmpDir)) + Directory.CreateDirectory(tmpDir); + + var tmpFile = Path.Combine(tmpDir, $"tmp_{DateTime.Now.ToString("ddMMyyyyHHmmss")}{fileName}.json"); + try { - var tmpDir = Path.Combine(_hostingEnvironment.ContentRootPath, "tmp"); - if (!Directory.Exists(tmpDir)) - Directory.CreateDirectory(tmpDir); - - fileName = $"{fileName}.json"; - tmpFile = Path.Combine(tmpDir, fileName); SaveToJsonFile(tmpFile, json); - await UploadFileAsyncTemp(tmpFile, path); } catch diff --git a/BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj b/BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj index a1f849a8..e73b2d88 100644 --- a/BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj +++ b/BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj @@ -12,6 +12,7 @@ + diff --git a/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs b/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs index 9dc06f9b..89b98e51 100644 --- a/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs +++ b/BMA.EHR.Retirement.Service/Controllers/RetirementController.cs @@ -269,24 +269,24 @@ namespace BMA.EHR.Retirement.Service.Controllers .Where(x => x.RetirementPeriod == retire) .Select(x => new { - Order = x.Order, - Id = x.Id, - Reason = x.Reason, - Remove = x.Remove, - ProfileId = x.Profile.Id, - CitizenId = x.Profile.CitizenId, - Prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, - FullName = $"{x.Profile.FirstName} {x.Profile.LastName}", - OrganizationOrganization = x.Profile.OrganizationOrganization, - Oc = x.Profile.Oc, - Position = x.Profile.Position == null ? null : x.Profile.Position.Name, - PositionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, - PositionExecutive = x.Profile.PositionExecutive, - PosNo = x.Profile.PosNo == null ? null : x.Profile.PosNo.Name, - PositionEmployeePosition = x.Profile.PositionEmployeePosition, - PositionEmployeeLevel = x.Profile.PositionEmployeeLevel, - PositionEmployeeGroup = x.Profile.PositionEmployeeGroup, - PosNoEmployee = x.Profile.PosNoEmployee, + order = x.Order, + id = x.Id, + reason = x.Reason, + remove = x.Remove, + profileId = x.Profile.Id, + citizenId = x.Profile.CitizenId, + prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, + fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", + organizationOrganization = x.Profile.OrganizationOrganization, + oc = x.Profile.Oc, + position = x.Profile.Position == null ? null : x.Profile.Position.Name, + positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, + positionExecutive = x.Profile.PositionExecutive, + posNo = x.Profile.PosNo == null ? null : x.Profile.PosNo.Name, + positionEmployeePosition = x.Profile.PositionEmployeePosition, + positionEmployeeLevel = x.Profile.PositionEmployeeLevel, + positionEmployeeGroup = x.Profile.PositionEmployeeGroup, + posNoEmployee = x.Profile.PosNoEmployee, }) .ToListAsync(); var profile = Newtonsoft.Json.JsonConvert.SerializeObject(profile_old); @@ -321,32 +321,47 @@ namespace BMA.EHR.Retirement.Service.Controllers { var profileHistorys = await _context.RetirementPeriodHistorys.AsQueryable() .FirstOrDefaultAsync(x => x.Id == req.RetireHistoryId); - if (profileHistorys == null) - return Error(GlobalMessages.InvalidRetirementHistoryRequest, 404); - using (var client = new HttpClient()) + + var profileOlds = new List(); + if (profileHistorys != null) { - var url = $"https://s3cluster.frappet.com/bma-ehr-fpt/retire/{profileHistorys.ProfileFile}"; - var responseTask = client.GetAsync(url); - var results = responseTask.Result; - var profileOlds = Newtonsoft.Json.JsonConvert.DeserializeObject>(results.Content.ReadAsStringAsync().Result); - if (profileOlds != null) + using (var client = new HttpClient()) { - foreach (var profileOld in profileOlds) + var url = $"https://s3cluster.frappet.com/bma-ehr-fpt/retire/{profileHistorys.ProfileFile}"; + var responseTask = client.GetAsync(url); + var results = responseTask.Result; + profileOlds = Newtonsoft.Json.JsonConvert.DeserializeObject>(results.Content.ReadAsStringAsync().Result); + } + } + else + { + var retireOld = await _context.RetirementPeriods + .FirstOrDefaultAsync(x => x.Id == req.RetireHistoryId); + if (retireOld == null) + return Error(GlobalMessages.InvalidRetirementRequest, 404); + profileOlds = await _context.RetirementProfiles.AsQueryable() + .Where(x => x.RetirementPeriod == retireOld) + .ToListAsync(); + } + if (profileOlds != null) + { + profileOlds = profileOlds.Where(x => !x.Remove.Trim().ToUpper().Contains("REMOVE")).ToList(); + foreach (var profileOld in profileOlds) + { + var data = new RetirementProfile { - var data = new RetirementProfile - { - Order = profileOld.Order, - Remove = "PENDING", - RetirementPeriod = retire, - Profile = profileOld.Profile, - CreatedUserId = profileOld.CreatedUserId, - CreatedFullName = profileOld.CreatedFullName, - CreatedAt = profileOld.CreatedAt, - LastUpdateFullName = profileOld.LastUpdateFullName, - LastUpdateUserId = profileOld.LastUpdateUserId, - LastUpdatedAt = profileOld.LastUpdatedAt, - }; - } + Order = profileOld.Order, + Remove = "PENDING", + RetirementPeriod = retire, + Profile = profileOld.Profile, + CreatedUserId = profileOld.CreatedUserId, + CreatedFullName = profileOld.CreatedFullName, + CreatedAt = profileOld.CreatedAt, + LastUpdateFullName = profileOld.LastUpdateFullName, + LastUpdateUserId = profileOld.LastUpdateUserId, + LastUpdatedAt = profileOld.LastUpdatedAt, + }; + retire.RetirementProfiles.Add(data); } } } @@ -358,24 +373,24 @@ namespace BMA.EHR.Retirement.Service.Controllers .Where(x => x.RetirementPeriod == retire) .Select(x => new { - Order = x.Order, - Id = x.Id, - Reason = x.Reason, - Remove = x.Remove, - ProfileId = x.Profile.Id, - CitizenId = x.Profile.CitizenId, - Prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, - FullName = $"{x.Profile.FirstName} {x.Profile.LastName}", - OrganizationOrganization = x.Profile.OrganizationOrganization, - Oc = x.Profile.Oc, - Position = x.Profile.Position == null ? null : x.Profile.Position.Name, - PositionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, - PositionExecutive = x.Profile.PositionExecutive, - PosNo = x.Profile.PosNo == null ? null : x.Profile.PosNo.Name, - PositionEmployeePosition = x.Profile.PositionEmployeePosition, - PositionEmployeeLevel = x.Profile.PositionEmployeeLevel, - PositionEmployeeGroup = x.Profile.PositionEmployeeGroup, - PosNoEmployee = x.Profile.PosNoEmployee, + order = x.Order, + id = x.Id, + reason = x.Reason, + remove = x.Remove, + profileId = x.Profile.Id, + citizenId = x.Profile.CitizenId, + prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, + fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", + organizationOrganization = x.Profile.OrganizationOrganization, + oc = x.Profile.Oc, + position = x.Profile.Position == null ? null : x.Profile.Position.Name, + positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, + positionExecutive = x.Profile.PositionExecutive, + posNo = x.Profile.PosNo == null ? null : x.Profile.PosNo.Name, + positionEmployeePosition = x.Profile.PositionEmployeePosition, + positionEmployeeLevel = x.Profile.PositionEmployeeLevel, + positionEmployeeGroup = x.Profile.PositionEmployeeGroup, + posNoEmployee = x.Profile.PosNoEmployee, }) .ToListAsync(); return Success(new { retire.Id, retire.CreatedAt, retire.Year, retire.Round, retire.Type, profile = profile_new }); @@ -404,15 +419,39 @@ namespace BMA.EHR.Retirement.Service.Controllers return Error(GlobalMessages.InvalidRetirementHistoryRequest, 404); using (var client = new HttpClient()) { - var url = $"https://s3cluster.frappet.com/bma-ehr-fpt/retire/{profileHistorys.ProfileFile}"; + var url = $"https://s3cluster.frappet.com/bma-ehr-fpt/retire/{profileHistorys.ProfileFile}.json"; var responseTask = client.GetAsync(url); var results = responseTask.Result; // Console.WriteLine(results.Content.ReadAsStringAsync().Result); - return Success(new { Json = true, profile = Newtonsoft.Json.JsonConvert.DeserializeObject>(results.Content.ReadAsStringAsync().Result) }); + return Success(new { Json = true, profile = Newtonsoft.Json.JsonConvert.DeserializeObject>(results.Content.ReadAsStringAsync().Result) }); } } + var profile_new = await _context.RetirementProfiles + .Where(x => x.RetirementPeriod == retire) + .Select(x => new + { + order = x.Order, + id = x.Id, + reason = x.Reason, + remove = x.Remove, + profileId = x.Profile.Id, + citizenId = x.Profile.CitizenId, + prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, + fullName = $"{x.Profile.FirstName} {x.Profile.LastName}", + organizationOrganization = x.Profile.OrganizationOrganization, + oc = x.Profile.Oc, + position = x.Profile.Position == null ? null : x.Profile.Position.Name, + positionType = x.Profile.PositionType == null ? null : x.Profile.PositionType.Name, + positionExecutive = x.Profile.PositionExecutive, + posNo = x.Profile.PosNo == null ? null : x.Profile.PosNo.Name, + positionEmployeePosition = x.Profile.PositionEmployeePosition, + positionEmployeeLevel = x.Profile.PositionEmployeeLevel, + positionEmployeeGroup = x.Profile.PositionEmployeeGroup, + posNoEmployee = x.Profile.PosNoEmployee, + }) + .ToListAsync(); - return Success(new { Json = false, profile = retire.RetirementProfiles }); + return Success(new { Json = false, profile = profile_new }); } /// diff --git a/BMA.EHR.Retirement.Service/tmp/20230803T211254.json b/BMA.EHR.Retirement.Service/tmp/20230803T211254.json new file mode 100644 index 00000000..c707dc95 --- /dev/null +++ b/BMA.EHR.Retirement.Service/tmp/20230803T211254.json @@ -0,0 +1 @@ +[{"order":2,"id":"08db93d9-a26b-4a93-8ecc-01f6bc4425b7","reason":"","remove":"PENDING","profileId":"08db721d-b171-45f1-845e-d78809081cfa","citizenId":"0000000000053","prefix":"นาย","fullName":"บล ตง","organizationOrganization":"กองพัฒนาระบบราชการกรุงเทพมหานคร","oc":"ปลัดกรุงเทพมหานคร/สำนักงานคณะกรรมการข้าราชการกรุงเทพมหานคร/กองพัฒนาระบบราชการกรุงเทพมหานคร","position":"ผู้อำนวยการ","positionType":"อำนวยการ","positionExecutive":"ผู้อำนวยการกอง","posNo":"กพร.1","positionEmployeePosition":null,"positionEmployeeLevel":null,"positionEmployeeGroup":null,"posNoEmployee":null},{"order":1,"id":"08db93d9-a26f-4d4e-885e-c996514222f2","reason":"","remove":"PENDING","profileId":"08db721d-b438-414e-861a-bd74b2cc8b03","citizenId":"0000000000088","prefix":"นาง","fullName":"สจ สว","organizationOrganization":"ส่วนโครงสร้างและอัตรากำลัง","oc":"ปลัดกรุงเทพมหานคร/สำนักงานคณะกรรมการข้าราชการกรุงเทพมหานคร/กองอัตรากำลัง/ส่วนโครงสร้างและอัตรากำลัง","position":"ผู้อำนวยการ","positionType":"อำนวยการ","positionExecutive":"ผู้อำนวยการส่วน","posNo":"กคอ.70","positionEmployeePosition":null,"positionEmployeeLevel":null,"positionEmployeeGroup":null,"posNoEmployee":null},{"order":4,"id":"08db93d9-a26f-4dbb-8afb-4bed0ac1c147","reason":"","remove":"PENDING","profileId":"08db721d-bb39-4902-8dab-dc582de20ab7","citizenId":"0000000000209","prefix":"นางสาว","fullName":"วณ มจ","organizationOrganization":"ฝ่ายบริหารงานทั่วไป","oc":"ปลัดกรุงเทพมหานคร/สำนักปลัดกรุงเทพมหานคร/สถาบันพัฒนาข้าราชการกรุงเทพมหานคร/ฝ่ายบริหารงานทั่วไป","position":"เจ้าพนักงานธุรการ","positionType":"ทั่วไป","positionExecutive":null,"posNo":"สพข.15","positionEmployeePosition":null,"positionEmployeeLevel":null,"positionEmployeeGroup":null,"posNoEmployee":null},{"order":3,"id":"08db93d9-a26f-4ddf-8c67-3ce67296b477","reason":"","remove":"PENDING","profileId":"08db721d-c0f0-4a43-820e-0d505da95a20","citizenId":"0000000000301","prefix":"นางสาว","fullName":"มร พจ","organizationOrganization":"ศูนย์การเรียนรู้มหานคร","oc":"ปลัดกรุงเทพมหานคร/สำนักปลัดกรุงเทพมหานคร/สถาบันพัฒนาข้าราชการกรุงเทพมหานคร/ศูนย์การเรียนรู้มหานคร","position":"นักจัดการงานทั่วไป","positionType":"วิชาการ","positionExecutive":"ผู้อำนวยการศูนย์","posNo":"สพข.107","positionEmployeePosition":null,"positionEmployeeLevel":null,"positionEmployeeGroup":null,"posNoEmployee":null}] \ No newline at end of file