From a9eb8d993ca98e7f4897f99202ad4ee9c6902df8 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 5 Sep 2024 10:50:58 +0700 Subject: [PATCH] fix report kk1/kp7 --- Controllers/ProfileReportController.cs | 895 +++++++++++++++---------- Responses/kk1Responses.cs | 139 ++++ Responses/kp7ShortRequest.cs | 9 +- 3 files changed, 686 insertions(+), 357 deletions(-) create mode 100644 Responses/kk1Responses.cs diff --git a/Controllers/ProfileReportController.cs b/Controllers/ProfileReportController.cs index bcfbff0..10660d0 100644 --- a/Controllers/ProfileReportController.cs +++ b/Controllers/ProfileReportController.cs @@ -81,15 +81,15 @@ namespace BMA.EHR.Report.Service.Controllers { try { - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptShortKp7.trdp"); + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptShortKp7.trdp"); - ReportPackager reportPackager = new ReportPackager(); - Telerik.Reporting.Report? report = null; - using (var sourceStream = System.IO.File.OpenRead(rptFile)) - { - report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); - } - var CitizenId = ""; + //ReportPackager reportPackager = new ReportPackager(); + //Telerik.Reporting.Report? report = null; + //using (var sourceStream = System.IO.File.OpenRead(rptFile)) + //{ + // report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); + //} + //var CitizenId = ""; var apiUrl = $"{_configuration["API"]}/org/profile/kp7-short/{id}"; using (var client = new HttpClient()) { @@ -99,43 +99,153 @@ namespace BMA.EHR.Report.Service.Controllers var _res = await client.SendAsync(_req); var _result = await _res.Content.ReadAsStringAsync(); - var org = JsonConvert.DeserializeObject(_result); + var data = JsonConvert.DeserializeObject(_result); - if (org == null || org.result == null) + if (data == null || data.result == null) { return Error("ไม่พบข้อมูลนี้ในระบบ", 404); } - report.DataSource = org.result; - CitizenId = org.result.CitizenId; - var tblEducation = (Telerik.Reporting.Table)report.Items["groupHeaderSection"].Items["tblEducation"]; - tblEducation.DataSource = org.result.Education; - // report.DataSource = data; - // if (profile.AvatarId != "") - // { - // try - // { - // // Get avatar Image - // var picContent = (await _minioService.DownloadFileAsync(Guid.Parse("00000000-0000-0000-0000-000000000000"))).FileContent; - // var pictureBox = (Telerik.Reporting.PictureBox)report.Items["groupHeaderSection"].Items["picAvatar"]; - // pictureBox.Value = Image.FromStream(new MemoryStream(picContent)); - // } - // catch { } - // } - - System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - - InstanceReportSource instanceReportSource = new InstanceReportSource() + var result = new { - ReportDocument = report + template = "kp7", + reportName = "docx-report", + data = new + { + FullName = data.result.Prefix != null && data.result.FirstName != null && data.result.LastName != null + ? $"{data.result.Prefix}{data.result.FirstName} {data.result.LastName}" : "-", + Prefix = data.result.Prefix != null ? data.result.Prefix : "-", + FirstName = data.result.FirstName != null ? data.result.FirstName : "-", + LastName = data.result.LastName != null ? data.result.LastName : "-", + CitizenId = data.result.CitizenId != null ? data.result.CitizenId : "-", + DateOfBirth = data.result.DateOfBirth != null ? data.result.DateOfBirth : "-", + DateRetire = data.result.DateRetire != null ? data.result.DateRetire : "-", + SalaryAmount = data.result.SalaryAmount != null ? data.result.SalaryAmount : "-", + RegistrationAddress = data.result.RegistrationAddress != null ? data.result.RegistrationAddress : "-", + SalaryDate = data.result.SalaryDate != null ? data.result.SalaryDate : "-", + PositionName = data.result.PositionName != null ? data.result.PositionName : "-", + AppointText = data.result.AppointText != null ? data.result.AppointText : "-", + OcFullPath = data.result.OcFullPath != null ? data.result.OcFullPath : "-", + Educations = data.result.Education != null && data.result.Education.Count > 0 + ? data.result.Education + : new List { + new Educations { + Institute = "-", + Date = "-", + Degree = "-", + }, + } + } }; + return Success(result); - ReportProcessor reportProcessor = new ReportProcessor(_configuration); - RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + //report.DataSource = org.result; + //CitizenId = org.result.CitizenId; + //var tblEducation = (Telerik.Reporting.Table)report.Items["groupHeaderSection"].Items["tblEducation"]; + //tblEducation.DataSource = org.result.Education; + //// report.DataSource = data; - var content = result.DocumentBytes; - return File(content, "application/pdf", $"ประวัติการรับราชการอย่างย่อ_.pdf"); + //// if (profile.AvatarId != "") + //// { + //// try + //// { + //// // Get avatar Image + //// var picContent = (await _minioService.DownloadFileAsync(Guid.Parse("00000000-0000-0000-0000-000000000000"))).FileContent; + //// var pictureBox = (Telerik.Reporting.PictureBox)report.Items["groupHeaderSection"].Items["picAvatar"]; + //// pictureBox.Value = Image.FromStream(new MemoryStream(picContent)); + //// } + //// catch { } + //// } + + //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + + //InstanceReportSource instanceReportSource = new InstanceReportSource() + //{ + // ReportDocument = report + //}; + + + //ReportProcessor reportProcessor = new ReportProcessor(_configuration); + //RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + + //var content = result.DocumentBytes; + //return File(content, "application/pdf", $"ประวัติการรับราชการอย่างย่อ_.pdf"); + } + } + catch (Exception ex) + { + return Error(ex, "ไม่สามารถแสดงผลรายงานได้!!!"); + } + } + + /// + /// แสดงประวัติการรับราชการแบบย่อ (ลูกจ้างประจำ) + /// + /// รหัสข้อมูลข้าราชการ + /// + /// เมื่อแสดงรายงานสำเร็จ + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + + [HttpGet("kp7-short-employee/{id:length(36)}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetKp7EmpShortReport(Guid id) + { + try + { + var apiUrl = $"{_configuration["API"]}/org/profile-employee/kp7-short/{id}"; + 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.Get, apiUrl); + var _res = await client.SendAsync(_req); + var _result = await _res.Content.ReadAsStringAsync(); + + var data = JsonConvert.DeserializeObject(_result); + + if (data == null || data.result == null) + { + return Error("ไม่พบข้อมูลนี้ในระบบ", 404); + } + + var result = new + { + template = "kp7", + reportName = "docx-report", + data = new + { + FullName = data.result.Prefix != null && data.result.FirstName != null && data.result.LastName != null + ? $"{data.result.Prefix}{data.result.FirstName} {data.result.LastName}" : "-", + Prefix = data.result.Prefix != null ? data.result.Prefix : "-", + FirstName = data.result.FirstName != null ? data.result.FirstName : "-", + LastName = data.result.LastName != null ? data.result.LastName : "-", + CitizenId = data.result.CitizenId != null ? data.result.CitizenId : "-", + DateOfBirth = data.result.DateOfBirth != null ? data.result.DateOfBirth : "-", + DateRetire = data.result.DateRetire != null ? data.result.DateRetire : "-", + SalaryAmount = data.result.SalaryAmount != null ? data.result.SalaryAmount : "-", + RegistrationAddress = data.result.RegistrationAddress != null ? data.result.RegistrationAddress : "-", + SalaryDate = data.result.SalaryDate != null ? data.result.SalaryDate : "-", + PositionName = data.result.PositionName != null ? data.result.PositionName : "-", + AppointText = data.result.AppointText != null ? data.result.AppointText : "-", + OcFullPath = data.result.OcFullPath != null ? data.result.OcFullPath : "-", + Educations = data.result.Education != null && data.result.Education.Count > 0 + ? data.result.Education + : new List { + new Educations { + Institute = "-", + Date = "-", + Degree = "-", + }, + } + } + }; + return Success(result); } } catch (Exception ex) @@ -162,23 +272,24 @@ namespace BMA.EHR.Report.Service.Controllers { try { - var rptFile0 = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Page0.trdp"); - ReportPackager reportPackager0 = new ReportPackager(); - Telerik.Reporting.Report? report0 = null; - using (var sourceStream0 = System.IO.File.OpenRead(rptFile0)) - { - report0 = (Telerik.Reporting.Report)reportPackager0.UnpackageDocument(sourceStream0); - } - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Page1.trdp"); - ReportPackager reportPackager = new ReportPackager(); - Telerik.Reporting.Report? report = null; - using (var sourceStream = System.IO.File.OpenRead(rptFile)) - { - report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); - } - var CitizenId = ""; - var FullName = ""; - var OcFullPath = ""; + + //var rptFile0 = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Page0.trdp"); + //ReportPackager reportPackager0 = new ReportPackager(); + //Telerik.Reporting.Report? report0 = null; + //using (var sourceStream0 = System.IO.File.OpenRead(rptFile0)) + //{ + // report0 = (Telerik.Reporting.Report)reportPackager0.UnpackageDocument(sourceStream0); + //} + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Page1.trdp"); + //ReportPackager reportPackager = new ReportPackager(); + //Telerik.Reporting.Report? report = null; + //using (var sourceStream = System.IO.File.OpenRead(rptFile)) + //{ + // report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); + //} + //var CitizenId = ""; + //var FullName = ""; + //var OcFullPath = ""; var apiUrl = $"{_configuration["API"]}/org/profile/kk1/{id}"; using (var client = new HttpClient()) { @@ -188,201 +299,237 @@ namespace BMA.EHR.Report.Service.Controllers var _res = await client.SendAsync(_req); var _result = await _res.Content.ReadAsStringAsync(); - var org = JsonConvert.DeserializeObject(_result); + var data = JsonConvert.DeserializeObject(_result); - if (org == null || org.result == null) + if (data == null || data.Result == null) { return Error("ไม่พบข้อมูลนี้ในระบบ", 404); } - report0.DataSource = org.result.Profile; - var tblInsignia = (Telerik.Reporting.Table)report0.Items["detailSection1"].Items["tblInsignia"]; - tblInsignia.DataSource = org.result.Insignia; - - var tblLeave = (Telerik.Reporting.Table)report0.Items["detailSection1"].Items["tblLeave"]; - tblLeave.DataSource = org.result.Leave; - - report.DataSource = org.result.Profile; - // binding to table - var tblCertificate = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblCertificate"]; - tblCertificate.DataSource = org.result.Cert; - - var tblTraining = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblTraining"]; - tblTraining.DataSource = org.result.Training; - - var tblDiscipline = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblDiscipline"]; - tblDiscipline.DataSource = org.result.Discipline; - - var tblEducation = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblEducation"]; - tblEducation.DataSource = org.result.Education; - var salary = org.result.Salary; - CitizenId = org.result.Profile[0].CitizenId; - FullName = org.result.Profile[0].FullName; - OcFullPath = org.result.Profile[0].OcFullPath; - - // if (profile.First().AvatarId != "") - // { - // try - // { - // // Get avatar Image - // var picContent = (await _minioService.DownloadFileAsync(Guid.Parse(profile.First().AvatarId))).FileContent; - // var pictureBox = (Telerik.Reporting.PictureBox)report.Items["pageFooterSection1"].Items["picAvatar"]; - // pictureBox.Value = Image.FromStream(new MemoryStream(picContent)); - // } - // catch { } - // } - - System.Collections.Hashtable deviceInfo0 = new System.Collections.Hashtable(); - InstanceReportSource instanceReportSource0 = new InstanceReportSource() + var result = new { - ReportDocument = report0 + template = "kk1", + reportName = "docx-report", + data = new + { + FullName = data.Result.Profile.Count > 0 ? $"{data.Result.Profile[0].Prefix}{data.Result.Profile[0].FirstName} {data.Result.Profile[0].LastName}" : "-", + Prefix = data.Result.Profile.Count > 0 ? data.Result.Profile[0].Prefix : "-", + FirstName = data.Result.Profile.Count > 0 ? data.Result.Profile[0].FirstName : "-", + LastName = data.Result.Profile.Count > 0 ? data.Result.Profile[0].LastName : "-", + OcFullPath = data.Result.Profile.Count > 0 ? data.Result.Profile[0].OcFullPath : "-", + BirthDate = data.Result.Profile.Count > 0 ? data.Result.Profile[0].BirthDate : "-", + RetireDate = data.Result.Profile.Count > 0 ? data.Result.Profile[0].RetireDate : "-", + AppointDate = data.Result.Profile.Count > 0 ? data.Result.Profile[0].AppointDate : "-", + CitizenId = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CitizenId : "-", + FatherFullName = data.Result.Profile.Count > 0 ? data.Result.Profile[0].FatherFullName : "-", + MotherFullName = data.Result.Profile.Count > 0 ? data.Result.Profile[0].MotherFullName : "-", + CoupleFullName = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CoupleFullName : "-", + CoupleLastNameOld = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CoupleLastNameOld : "-", + CurrentAddress = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CurrentAddress : "-", + CurrentSubDistrict = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CurrentSubDistrict : "-", + CurrentDistrict = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CurrentDistrict : "-", + CurrentProvince = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CurrentProvince : "-", + Telephone = data.Result.Profile.Count > 0 ? data.Result.Profile[0].Telephone : "-", + Insignias = data.Result.Insignia, + Leaves = data.Result.Leave, + Certs = data.Result.Cert, + Trainings = data.Result.Training, + Disciplines = data.Result.Discipline, + Educations = data.Result.Education, + Salarys = data.Result.Salary, + } }; - ReportProcessor reportProcessor0 = new ReportProcessor(_configuration); - RenderingResult result0 = reportProcessor0.RenderReport("PDF", instanceReportSource0, deviceInfo0); - var content0 = result0.DocumentBytes; + return Success(result); - System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + //report0.DataSource = org.result.Profile; + //var tblInsignia = (Telerik.Reporting.Table)report0.Items["detailSection1"].Items["tblInsignia"]; + //tblInsignia.DataSource = org.result.Insignia; - InstanceReportSource instanceReportSource = new InstanceReportSource() - { - ReportDocument = report - }; + //var tblLeave = (Telerik.Reporting.Table)report0.Items["detailSection1"].Items["tblLeave"]; + //tblLeave.DataSource = org.result.Leave; + //report.DataSource = org.result.Profile; + //// binding to table + //var tblCertificate = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblCertificate"]; + //tblCertificate.DataSource = org.result.Cert; - ReportProcessor reportProcessor = new ReportProcessor(_configuration); - RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + //var tblTraining = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblTraining"]; + //tblTraining.DataSource = org.result.Training; - // byte array waiting for merge pdf - var content = result.DocumentBytes; + //var tblDiscipline = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblDiscipline"]; + //tblDiscipline.DataSource = org.result.Discipline; - // // page2 - // var profile2 = (from p in _context.Profiles - // join pf in _context.Prefixes on p.PrefixId equals pf.Id - // where p.Id == id - // select new - // { - // FullName = $"{pf.Name}{p.FirstName} {p.LastName}", - // OcFullPath = _profileService.GetOrganizationNameFullPath(p.OcId.Value, false, false), - // }).FirstOrDefault(); + //var tblEducation = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblEducation"]; + //tblEducation.DataSource = org.result.Education; + //var salary = org.result.Salary; + //CitizenId = org.result.Profile[0].CitizenId; + //FullName = org.result.Profile[0].FullName; + //OcFullPath = org.result.Profile[0].OcFullPath; - // var salary = (from s in _context.ProfileSalaries - // .Include(x => x.PositionLevel) - // join pos in _context.PositionPaths.AsQueryable() - // on s.PositionId equals pos.Id - // join pos_no in _context.PositionNumbers on s.PosNoId equals pos_no.Id - // // join pos_lv in _context.PositionLevels on s.PositionLevelId equals pos_lv.Id - // join pos_type in _context.PositionTypes on s.PositionTypeId equals pos_type.Id - // where s.Profile.Id == id - // orderby s.Date.Value - // select new - // { - // SalaryDate = s.Date == null ? "" : s.Date == new DateTime(1, 1, 1) ? "" : s.Date.Value.ToThaiShortDate(), - // Position = $"{pos.Name} ประเภท{pos_type.Name} ระดับ{s.PositionLevel.Name}", - // PosNo = pos_no.Name, - // Rank = s.PositionLevel == null ? null : s.PositionLevel.Name, - // Salary = s.Amount == null ? "" : s.Amount == 0 ? "-" : s.Amount.ToString().ToInteger().ToNumericText(), - // RefAll = s.SalaryRef, - // PositionType = pos_type.Name, - // PositionLevel = s.PositionLevel == null ? null : s.PositionLevel.Name, - // PositionAmount = s.PositionSalaryAmount == null ? "" : s.PositionSalaryAmount.Value == 0 ? "-" : s.PositionSalaryAmount.Value.ToString().ToInteger().ToNumericText(), - // FullName = profile2.FullName, - // OcFullPath = profile2.OcFullPath - // }).ToList(); + //// if (profile.First().AvatarId != "") + //// { + //// try + //// { + //// // Get avatar Image + //// var picContent = (await _minioService.DownloadFileAsync(Guid.Parse(profile.First().AvatarId))).FileContent; + //// var pictureBox = (Telerik.Reporting.PictureBox)report.Items["pageFooterSection1"].Items["picAvatar"]; + //// pictureBox.Value = Image.FromStream(new MemoryStream(picContent)); + //// } + //// catch { } + //// } - //while (salary.Count < 60) + //System.Collections.Hashtable deviceInfo0 = new System.Collections.Hashtable(); + //InstanceReportSource instanceReportSource0 = new InstanceReportSource() //{ - // salary.Add(new - // { - // SalaryDate = "", - // Position = "", - // PosNo = "", - // Rank = "", - // Salary = "", - // RefAll = "", - // PositionType = "", - // PositionLevel = "", - // PositionAmount = "", - // FullName = profile2.FullName, - // OcFullPath = profile2.OcFullPath - // }); + // ReportDocument = report0 + //}; + + //ReportProcessor reportProcessor0 = new ReportProcessor(_configuration); + //RenderingResult result0 = reportProcessor0.RenderReport("PDF", instanceReportSource0, deviceInfo0); + //var content0 = result0.DocumentBytes; + + //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + + //InstanceReportSource instanceReportSource = new InstanceReportSource() + //{ + // ReportDocument = report + //}; + + + //ReportProcessor reportProcessor = new ReportProcessor(_configuration); + //RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + + //// byte array waiting for merge pdf + //var content = result.DocumentBytes; + + //// // page2 + //// var profile2 = (from p in _context.Profiles + //// join pf in _context.Prefixes on p.PrefixId equals pf.Id + //// where p.Id == id + //// select new + //// { + //// FullName = $"{pf.Name}{p.FirstName} {p.LastName}", + //// OcFullPath = _profileService.GetOrganizationNameFullPath(p.OcId.Value, false, false), + //// }).FirstOrDefault(); + + //// var salary = (from s in _context.ProfileSalaries + //// .Include(x => x.PositionLevel) + //// join pos in _context.PositionPaths.AsQueryable() + //// on s.PositionId equals pos.Id + //// join pos_no in _context.PositionNumbers on s.PosNoId equals pos_no.Id + //// // join pos_lv in _context.PositionLevels on s.PositionLevelId equals pos_lv.Id + //// join pos_type in _context.PositionTypes on s.PositionTypeId equals pos_type.Id + //// where s.Profile.Id == id + //// orderby s.Date.Value + //// select new + //// { + //// SalaryDate = s.Date == null ? "" : s.Date == new DateTime(1, 1, 1) ? "" : s.Date.Value.ToThaiShortDate(), + //// Position = $"{pos.Name} ประเภท{pos_type.Name} ระดับ{s.PositionLevel.Name}", + //// PosNo = pos_no.Name, + //// Rank = s.PositionLevel == null ? null : s.PositionLevel.Name, + //// Salary = s.Amount == null ? "" : s.Amount == 0 ? "-" : s.Amount.ToString().ToInteger().ToNumericText(), + //// RefAll = s.SalaryRef, + //// PositionType = pos_type.Name, + //// PositionLevel = s.PositionLevel == null ? null : s.PositionLevel.Name, + //// PositionAmount = s.PositionSalaryAmount == null ? "" : s.PositionSalaryAmount.Value == 0 ? "-" : s.PositionSalaryAmount.Value.ToString().ToInteger().ToNumericText(), + //// FullName = profile2.FullName, + //// OcFullPath = profile2.OcFullPath + //// }).ToList(); + + ////while (salary.Count < 60) + ////{ + //// salary.Add(new + //// { + //// SalaryDate = "", + //// Position = "", + //// PosNo = "", + //// Rank = "", + //// Salary = "", + //// RefAll = "", + //// PositionType = "", + //// PositionLevel = "", + //// PositionAmount = "", + //// FullName = profile2.FullName, + //// OcFullPath = profile2.OcFullPath + //// }); + ////} + + //var rptFile2 = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Page2.trdp"); + + //ReportPackager reportPackager2 = new ReportPackager(); + //Telerik.Reporting.Report? report2 = null; + //using (var sourceStream = System.IO.File.OpenRead(rptFile2)) + //{ + // report2 = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); //} - var rptFile2 = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Page2.trdp"); + //report2.ReportParameters["FullName"].Value = FullName; + //report2.ReportParameters["OcFullPath"].Value = OcFullPath; - ReportPackager reportPackager2 = new ReportPackager(); - Telerik.Reporting.Report? report2 = null; - using (var sourceStream = System.IO.File.OpenRead(rptFile2)) - { - report2 = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); - } + //// binding to table + //var tblSalary = (Telerik.Reporting.Table)report2.Items["detailSection1"].Items["tblSalary"]; + //tblSalary.DataSource = salary; - report2.ReportParameters["FullName"].Value = FullName; - report2.ReportParameters["OcFullPath"].Value = OcFullPath; + //System.Collections.Hashtable deviceInfo2 = new System.Collections.Hashtable(); - // binding to table - var tblSalary = (Telerik.Reporting.Table)report2.Items["detailSection1"].Items["tblSalary"]; - tblSalary.DataSource = salary; - - System.Collections.Hashtable deviceInfo2 = new System.Collections.Hashtable(); - - InstanceReportSource instanceReportSource2 = new InstanceReportSource() - { - ReportDocument = report2 - }; + //InstanceReportSource instanceReportSource2 = new InstanceReportSource() + //{ + // ReportDocument = report2 + //}; - ReportProcessor reportProcessor2 = new ReportProcessor(_configuration); - RenderingResult result2 = reportProcessor2.RenderReport("PDF", instanceReportSource2, deviceInfo2); + //ReportProcessor reportProcessor2 = new ReportProcessor(_configuration); + //RenderingResult result2 = reportProcessor2.RenderReport("PDF", instanceReportSource2, deviceInfo2); - // byte array waiting for merge pdf - var content2 = result2.DocumentBytes; + //// byte array waiting for merge pdf + //var content2 = result2.DocumentBytes; - // merge pdf - using (MemoryStream ms = new MemoryStream()) - { - using (PdfDocument pdf = new PdfDocument(new PdfWriter(ms).SetSmartMode(true))) - { - using (MemoryStream memoryStream = new MemoryStream(content0)) - { - using (PdfReader reader = new PdfReader(memoryStream)) - { - PdfDocument srcDoc = new PdfDocument(reader); - srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); - } - } + //// merge pdf + //using (MemoryStream ms = new MemoryStream()) + //{ + // using (PdfDocument pdf = new PdfDocument(new PdfWriter(ms).SetSmartMode(true))) + // { + // using (MemoryStream memoryStream = new MemoryStream(content0)) + // { + // using (PdfReader reader = new PdfReader(memoryStream)) + // { + // PdfDocument srcDoc = new PdfDocument(reader); + // srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); + // } + // } - // Create reader from bytes - using (MemoryStream memoryStream = new MemoryStream(content)) - { - // Create reader from bytes - using (PdfReader reader = new PdfReader(memoryStream)) - { - PdfDocument srcDoc = new PdfDocument(reader); - srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); - } - } + // // Create reader from bytes + // using (MemoryStream memoryStream = new MemoryStream(content)) + // { + // // Create reader from bytes + // using (PdfReader reader = new PdfReader(memoryStream)) + // { + // PdfDocument srcDoc = new PdfDocument(reader); + // srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); + // } + // } - // Create reader from bytes - if (content2 != null) - { - using (MemoryStream memoryStream = new MemoryStream(content2)) - { - // Create reader from bytes - using (PdfReader reader = new PdfReader(memoryStream)) - { - PdfDocument srcDoc = new PdfDocument(reader); - srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); - } - } - } + // // Create reader from bytes + // if (content2 != null) + // { + // using (MemoryStream memoryStream = new MemoryStream(content2)) + // { + // // Create reader from bytes + // using (PdfReader reader = new PdfReader(memoryStream)) + // { + // PdfDocument srcDoc = new PdfDocument(reader); + // srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); + // } + // } + // } - pdf.Close(); - } + // pdf.Close(); + // } - var fileContent = ms.ToArray(); - return File(fileContent, "application/pdf", $"กก_1_{CitizenId}.pdf"); - } + // var fileContent = ms.ToArray(); + // return File(fileContent, "application/pdf", $"กก_1_{CitizenId}.pdf"); + //} } } @@ -410,23 +557,23 @@ namespace BMA.EHR.Report.Service.Controllers { try { - var rptFile0 = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Emp_Page0.trdp"); - ReportPackager reportPackager0 = new ReportPackager(); - Telerik.Reporting.Report? report0 = null; - using (var sourceStream0 = System.IO.File.OpenRead(rptFile0)) - { - report0 = (Telerik.Reporting.Report)reportPackager0.UnpackageDocument(sourceStream0); - } - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Emp_Page1.trdp"); - ReportPackager reportPackager = new ReportPackager(); - Telerik.Reporting.Report? report = null; - using (var sourceStream = System.IO.File.OpenRead(rptFile)) - { - report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); - } - var CitizenId = ""; - var FullName = ""; - var OcFullPath = ""; + //var rptFile0 = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Emp_Page0.trdp"); + //ReportPackager reportPackager0 = new ReportPackager(); + //Telerik.Reporting.Report? report0 = null; + //using (var sourceStream0 = System.IO.File.OpenRead(rptFile0)) + //{ + // report0 = (Telerik.Reporting.Report)reportPackager0.UnpackageDocument(sourceStream0); + //} + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Emp_Page1.trdp"); + //ReportPackager reportPackager = new ReportPackager(); + //Telerik.Reporting.Report? report = null; + //using (var sourceStream = System.IO.File.OpenRead(rptFile)) + //{ + // report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); + //} + //var CitizenId = ""; + //var FullName = ""; + //var OcFullPath = ""; var apiUrl = $"{_configuration["API"]}/org/profile-employee/kk1/{id}"; using (var client = new HttpClient()) { @@ -436,137 +583,173 @@ namespace BMA.EHR.Report.Service.Controllers var _res = await client.SendAsync(_req); var _result = await _res.Content.ReadAsStringAsync(); - var org = JsonConvert.DeserializeObject(_result); + var data = JsonConvert.DeserializeObject(_result); - if (org == null || org.result == null) + if (data == null || data.Result == null) { return Error("ไม่พบข้อมูลนี้ในระบบ", 404); } - report0.DataSource = org.result.Profile; - var tblInsignia = (Telerik.Reporting.Table)report0.Items["detailSection1"].Items["tblInsignia"]; - tblInsignia.DataSource = org.result.Insignia; - - var tblLeave = (Telerik.Reporting.Table)report0.Items["detailSection1"].Items["tblLeave"]; - tblLeave.DataSource = org.result.Leave; - - report.DataSource = org.result.Profile; - // binding to table - var tblCertificate = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblCertificate"]; - tblCertificate.DataSource = org.result.Cert; - - var tblTraining = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblTraining"]; - tblTraining.DataSource = org.result.Training; - - var tblDiscipline = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblDiscipline"]; - tblDiscipline.DataSource = org.result.Discipline; - - var tblEducation = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblEducation"]; - tblEducation.DataSource = org.result.Education; - var salary = org.result.Salary; - CitizenId = org.result.Profile[0].CitizenId; - FullName = org.result.Profile[0].FullName; - OcFullPath = org.result.Profile[0].OcFullPath; - - System.Collections.Hashtable deviceInfo0 = new System.Collections.Hashtable(); - InstanceReportSource instanceReportSource0 = new InstanceReportSource() + var result = new { - ReportDocument = report0 - }; - - ReportProcessor reportProcessor0 = new ReportProcessor(_configuration); - RenderingResult result0 = reportProcessor0.RenderReport("PDF", instanceReportSource0, deviceInfo0); - var content0 = result0.DocumentBytes; - - System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); - - InstanceReportSource instanceReportSource = new InstanceReportSource() - { - ReportDocument = report - }; - - - ReportProcessor reportProcessor = new ReportProcessor(_configuration); - RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); - - // byte array waiting for merge pdf - var content = result.DocumentBytes; - - var rptFile2 = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Emp_Page2.trdp"); - - ReportPackager reportPackager2 = new ReportPackager(); - Telerik.Reporting.Report? report2 = null; - using (var sourceStream = System.IO.File.OpenRead(rptFile2)) - { - report2 = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); - } - - report2.ReportParameters["FullName"].Value = FullName; - report2.ReportParameters["OcFullPath"].Value = OcFullPath; - - // binding to table - var tblSalary = (Telerik.Reporting.Table)report2.Items["detailSection1"].Items["tblSalary"]; - tblSalary.DataSource = salary; - - System.Collections.Hashtable deviceInfo2 = new System.Collections.Hashtable(); - - InstanceReportSource instanceReportSource2 = new InstanceReportSource() - { - ReportDocument = report2 - }; - - - ReportProcessor reportProcessor2 = new ReportProcessor(_configuration); - RenderingResult result2 = reportProcessor2.RenderReport("PDF", instanceReportSource2, deviceInfo2); - - // byte array waiting for merge pdf - var content2 = result2.DocumentBytes; - - // merge pdf - using (MemoryStream ms = new MemoryStream()) - { - using (PdfDocument pdf = new PdfDocument(new PdfWriter(ms).SetSmartMode(true))) + template = "kk1-emp", + reportName = "docx-report", + data = new { - using (MemoryStream memoryStream = new MemoryStream(content0)) - { - using (PdfReader reader = new PdfReader(memoryStream)) - { - PdfDocument srcDoc = new PdfDocument(reader); - srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); - } - } - - // Create reader from bytes - using (MemoryStream memoryStream = new MemoryStream(content)) - { - // Create reader from bytes - using (PdfReader reader = new PdfReader(memoryStream)) - { - PdfDocument srcDoc = new PdfDocument(reader); - srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); - } - } - - // Create reader from bytes - if (content2 != null) - { - using (MemoryStream memoryStream = new MemoryStream(content2)) - { - // Create reader from bytes - using (PdfReader reader = new PdfReader(memoryStream)) - { - PdfDocument srcDoc = new PdfDocument(reader); - srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); - } - } - } - - pdf.Close(); + FullName = data.Result.Profile.Count > 0 ? $"{data.Result.Profile[0].Prefix}{data.Result.Profile[0].FirstName} {data.Result.Profile[0].LastName}" : "-", + Prefix = data.Result.Profile.Count > 0 ? data.Result.Profile[0].Prefix : "-", + FirstName = data.Result.Profile.Count > 0 ? data.Result.Profile[0].FirstName : "-", + LastName = data.Result.Profile.Count > 0 ? data.Result.Profile[0].LastName : "-", + OcFullPath = data.Result.Profile.Count > 0 ? data.Result.Profile[0].OcFullPath : "-", + BirthDate = data.Result.Profile.Count > 0 ? data.Result.Profile[0].BirthDate : "-", + RetireDate = data.Result.Profile.Count > 0 ? data.Result.Profile[0].RetireDate : "-", + AppointDate = data.Result.Profile.Count > 0 ? data.Result.Profile[0].AppointDate : "-", + CitizenId = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CitizenId : "-", + FatherFullName = data.Result.Profile.Count > 0 ? data.Result.Profile[0].FatherFullName : "-", + MotherFullName = data.Result.Profile.Count > 0 ? data.Result.Profile[0].MotherFullName : "-", + CoupleFullName = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CoupleFullName : "-", + CoupleLastNameOld = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CoupleLastNameOld : "-", + CurrentAddress = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CurrentAddress : "-", + CurrentSubDistrict = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CurrentSubDistrict : "-", + CurrentDistrict = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CurrentDistrict : "-", + CurrentProvince = data.Result.Profile.Count > 0 ? data.Result.Profile[0].CurrentProvince : "-", + Telephone = data.Result.Profile.Count > 0 ? data.Result.Profile[0].Telephone : "-", + Insignias = data.Result.Insignia, + Leaves = data.Result.Leave, + Certs = data.Result.Cert, + Trainings = data.Result.Training, + Disciplines = data.Result.Discipline, + Educations = data.Result.Education, + Salarys = data.Result.Salary, } + }; - var fileContent = ms.ToArray(); - return File(fileContent, "application/pdf", $"กก_1_{CitizenId}.pdf"); - } + return Success(result); + + //report0.DataSource = org.result.Profile; + //var tblInsignia = (Telerik.Reporting.Table)report0.Items["detailSection1"].Items["tblInsignia"]; + //tblInsignia.DataSource = org.result.Insignia; + + //var tblLeave = (Telerik.Reporting.Table)report0.Items["detailSection1"].Items["tblLeave"]; + //tblLeave.DataSource = org.result.Leave; + + //report.DataSource = org.result.Profile; + //// binding to table + //var tblCertificate = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblCertificate"]; + //tblCertificate.DataSource = org.result.Cert; + + //var tblTraining = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblTraining"]; + //tblTraining.DataSource = org.result.Training; + + //var tblDiscipline = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblDiscipline"]; + //tblDiscipline.DataSource = org.result.Discipline; + + //var tblEducation = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblEducation"]; + //tblEducation.DataSource = org.result.Education; + //var salary = org.result.Salary; + //CitizenId = org.result.Profile[0].CitizenId; + //FullName = org.result.Profile[0].FullName; + //OcFullPath = org.result.Profile[0].OcFullPath; + + //System.Collections.Hashtable deviceInfo0 = new System.Collections.Hashtable(); + //InstanceReportSource instanceReportSource0 = new InstanceReportSource() + //{ + // ReportDocument = report0 + //}; + + //ReportProcessor reportProcessor0 = new ReportProcessor(_configuration); + //RenderingResult result0 = reportProcessor0.RenderReport("PDF", instanceReportSource0, deviceInfo0); + //var content0 = result0.DocumentBytes; + + //System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + + //InstanceReportSource instanceReportSource = new InstanceReportSource() + //{ + // ReportDocument = report + //}; + + + //ReportProcessor reportProcessor = new ReportProcessor(_configuration); + //RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo); + + //// byte array waiting for merge pdf + //var content = result.DocumentBytes; + + //var rptFile2 = Path.Combine(_hostingEnvironment.ContentRootPath, "Report", "Profile", $"rptKK1_Emp_Page2.trdp"); + + //ReportPackager reportPackager2 = new ReportPackager(); + //Telerik.Reporting.Report? report2 = null; + //using (var sourceStream = System.IO.File.OpenRead(rptFile2)) + //{ + // report2 = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); + //} + + //report2.ReportParameters["FullName"].Value = FullName; + //report2.ReportParameters["OcFullPath"].Value = OcFullPath; + + //// binding to table + //var tblSalary = (Telerik.Reporting.Table)report2.Items["detailSection1"].Items["tblSalary"]; + //tblSalary.DataSource = salary; + + //System.Collections.Hashtable deviceInfo2 = new System.Collections.Hashtable(); + + //InstanceReportSource instanceReportSource2 = new InstanceReportSource() + //{ + // ReportDocument = report2 + //}; + + + //ReportProcessor reportProcessor2 = new ReportProcessor(_configuration); + //RenderingResult result2 = reportProcessor2.RenderReport("PDF", instanceReportSource2, deviceInfo2); + + //// byte array waiting for merge pdf + //var content2 = result2.DocumentBytes; + + //// merge pdf + //using (MemoryStream ms = new MemoryStream()) + //{ + // using (PdfDocument pdf = new PdfDocument(new PdfWriter(ms).SetSmartMode(true))) + // { + // using (MemoryStream memoryStream = new MemoryStream(content0)) + // { + // using (PdfReader reader = new PdfReader(memoryStream)) + // { + // PdfDocument srcDoc = new PdfDocument(reader); + // srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); + // } + // } + + // // Create reader from bytes + // using (MemoryStream memoryStream = new MemoryStream(content)) + // { + // // Create reader from bytes + // using (PdfReader reader = new PdfReader(memoryStream)) + // { + // PdfDocument srcDoc = new PdfDocument(reader); + // srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); + // } + // } + + // // Create reader from bytes + // if (content2 != null) + // { + // using (MemoryStream memoryStream = new MemoryStream(content2)) + // { + // // Create reader from bytes + // using (PdfReader reader = new PdfReader(memoryStream)) + // { + // PdfDocument srcDoc = new PdfDocument(reader); + // srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf); + // } + // } + // } + + // pdf.Close(); + // } + + // var fileContent = ms.ToArray(); + // return File(fileContent, "application/pdf", $"กก_1_{CitizenId}.pdf"); + //} } } diff --git a/Responses/kk1Responses.cs b/Responses/kk1Responses.cs new file mode 100644 index 0000000..b241c6c --- /dev/null +++ b/Responses/kk1Responses.cs @@ -0,0 +1,139 @@ +using BMA.EHR.MetaData.Service.Models; +using BMA.EHR.Recurit.Exam.Service.Models; +using DnsClient; +using Microsoft.EntityFrameworkCore; +using System.Runtime.ConstrainedExecution; + +namespace BMA.EHR.Report.Service.Responses +{ + public class kk1Responses + { + public string Status { get; set; } + public string Message { get; set; } + public Data Result { get; set; } + + public class Data + { + public List Profile { get; set; } + public List Insignia { get; set; } + public List Leave { get; set; } + public List Cert { get; set; } + public List Training { get; set; } + public List Discipline { get; set; } + public List Education { get; set; } + public List Salary { get; set; } + } + + public class Profile + { + public string? CitizenId { get; set; } + public string? Prefix { get; set; } + public string? FirstName { get; set; } + public string? LastName { get; set; } + public string? FullName { get; set; } + public string? BirthDay { get; set; } + public string? BirthDayText { get; set; } + public string? BirthMonth { get; set; } + public string? BirthYear { get; set; } + public string? BirthYearText { get; set; } + public string? Address { get; set; } + public string? District { get; set; } + public string? Area { get; set; } + public string? Province { get; set; } + public string? Telephone { get; set; } + public string? CoupleLastNameOld { get; set; } + public string? CouplePrefix { get; set; } + public string? CoupleFullName { get; set; } + public string? FatherPrefix { get; set; } + public string? FatherFullName { get; set; } + public string? MotherPrefix { get; set; } + public string? MotherFullName { get; set; } + public string? OcFullPath { get; set; } + public string? Division { get; set; } + public string? Institute { get; set; } + public string? StartDate { get; set; } + public string? AppointDate { get; set; } + public string? BirthDate { get; set; } + public string? RetireDate { get; set; } + public string? CurrentAddress { get; set; } + public string? CurrentSubDistrict { get; set; } + public string? CurrentDistrict { get; set; } + public string? CurrentProvince { get; set; } + } + + public class Insignia + { + public string? ReceiveDate { get; set; } + public string? InsigniaName { get; set; } + public string? InsigniaShortName { get; set; } + public string? InsigniaTypeName { get; set; } + public string? No { get; set; } + public string? Issue { get; set; } + public string? VolumeNo { get; set; } + public string? Volume { get; set; } + public string? Section { get; set; } + public string? Page { get; set; } + public string? RefCommandDate { get; set; } + } + + public class Leave + { + public string? LeaveTypeName { get; set; } + public string? DateLeaveStart { get; set; } + public string? LeaveDays { get; set; } + } + + public class Cert + { + public string? CertificateType { get; set; } + public string? Issuer { get; set; } + public string? CertificateNo { get; set; } + public string? IssueDate { get; set; } + } + + public class Training + { + public string? Institute { get; set; } + public string? Start { get; set; } + public string? End { get; set; } + public string? Date { get; set; } + public string? Level { get; set; } + public string? Degree { get; set; } + public string? Field { get; set; } + } + + public class Discipline + { + public string? DisciplineYear { get; set; } + public string? DisciplineDetail { get; set; } + public string? RefNo { get; set; } + } + + public class Education + { + public string? Institute { get; set; } + public string? Start { get; set; } + public string? End { get; set; } + public string? Date { get; set; } + public string? Level { get; set; } + public string? Degree { get; set; } + public string? Field { get; set; } + } + + public class Salaries + { + public string? SalaryDate { get; set; } + public string? Position { get; set; } + public string? PosNo { get; set; } + public string? Salary { get; set; } + public string? Rank { get; set; } + public string? RefAll { get; set; } + public string? PositionLevel { get; set; } + public string? PositionType { get; set; } + public string? PositionAmount { get; set; } + public string? FullName { get; set; } + public string? OcFullPath { get; set; } + } + + } +} \ No newline at end of file diff --git a/Responses/kp7ShortRequest.cs b/Responses/kp7ShortRequest.cs index 83df103..578f53c 100644 --- a/Responses/kp7ShortRequest.cs +++ b/Responses/kp7ShortRequest.cs @@ -16,10 +16,17 @@ namespace BMA.EHR.Report.Service.Responses public string? DateRetire { get; set; } public string? RegistrationAddress { get; set; } public string? SalaryAmount { get; set; } - public List Education { get; set; } + public List Education { get; set; } public string? AppointText { get; set; } public string? SalaryDate { get; set; } public string? PositionName { get; set; } public string? OcFullPath { get; set; } } + + public class Educations + { + public string? Institute { get; set; } + public string? Date { get; set; } + public string? Degree { get; set; } + } } \ No newline at end of file