From f386a5fea62bcef6ac012edff794b3a72bd3c2a3 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 18 Aug 2023 02:25:07 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=88=E0=B8=B1=E0=B8=94=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B8=84=E0=B8=B3=E0=B8=82=E0=B8=AD=E0=B9=80?= =?UTF-8?q?=E0=B8=84=E0=B8=A3=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=87=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/InsigniaPeriodsRepository.cs | 5 +- .../Requests/InsigniaPeriodRequest.cs | 4 +- .../Requests/InsigniaRequestItem.cs | 1 + .../Models/Insignias/InsigniaPeriod.cs | 4 +- .../Insignias/InsigniaRequestProfile.cs | 3 + BMA.EHR.Domain/Shared/GlobalMessages.cs | 1 + .../Controllers/InsigniaPeriodController.cs | 40 +- .../Controllers/InsigniaRequestController.cs | 584 +++++++++++------- 8 files changed, 409 insertions(+), 233 deletions(-) diff --git a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs index 136e0539..9a3851d9 100644 --- a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs +++ b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs @@ -4932,7 +4932,7 @@ namespace BMA.EHR.Application.Repositories // } // Get Data Table insignai_has_profile - public async Task> InsigniaHasProfile(Guid period, Guid ocId) + public async Task> InsigniaHasProfile(Guid period, Guid ocId, string status) { try { @@ -4960,6 +4960,7 @@ namespace BMA.EHR.Application.Repositories .Include(x => x.Profile) .ThenInclude(x => x.Insignias) .ThenInclude(x => x.Insignia) + .Where(h => status.Trim().ToUpper() == "ALL" ? h.Status != null : h.Status == status.Trim().ToUpper()) .Where(h => h.Request.Id == id) .ToList() .Select(h => new InsigniaRequestItem @@ -4976,6 +4977,7 @@ namespace BMA.EHR.Application.Repositories Level = h.RequestInsignia.InsigniaType.Name, IsApprove = h.IsApprove, RequestDate = h.RequestDate, + Status = h.Status, RequestNote = "", // Docs = GetDocFile(h.Profile.Id), MatchingConditions = h.MatchingConditions == null ? null : JsonConvert.DeserializeObject>(h.MatchingConditions) @@ -5119,6 +5121,7 @@ namespace BMA.EHR.Application.Repositories { req.RequestProfiles.Add(new InsigniaRequestProfile { + Status = "PENDING", Profile = pf, RequestInsignia = req_insignia, Salary = item.Salary == null ? null : item.Salary, diff --git a/BMA.EHR.Application/Requests/InsigniaPeriodRequest.cs b/BMA.EHR.Application/Requests/InsigniaPeriodRequest.cs index 990c2770..a653089a 100644 --- a/BMA.EHR.Application/Requests/InsigniaPeriodRequest.cs +++ b/BMA.EHR.Application/Requests/InsigniaPeriodRequest.cs @@ -13,9 +13,9 @@ namespace BMA.EHR.Application.Requests public DateTime EndDate { get; set; } - public string Amount { get; set; } + public int Amount { get; set; } - // public string Type { get; set; } + public int Round { get; set; } public FormFile? File { get; set; } } } diff --git a/BMA.EHR.Application/Requests/InsigniaRequestItem.cs b/BMA.EHR.Application/Requests/InsigniaRequestItem.cs index 94bfacd1..f39b7460 100644 --- a/BMA.EHR.Application/Requests/InsigniaRequestItem.cs +++ b/BMA.EHR.Application/Requests/InsigniaRequestItem.cs @@ -12,6 +12,7 @@ public string RequestInsignia { get; set; } public string RequestInsigniaShortName { get; set; } public string Level { get; set; } + public string Status { get; set; } public bool IsApprove { get; set; } public DateTime? RequestDate { get; set; } public string RequestNote { get; set; } diff --git a/BMA.EHR.Domain/Models/Insignias/InsigniaPeriod.cs b/BMA.EHR.Domain/Models/Insignias/InsigniaPeriod.cs index f64ddafa..5a748e0d 100644 --- a/BMA.EHR.Domain/Models/Insignias/InsigniaPeriod.cs +++ b/BMA.EHR.Domain/Models/Insignias/InsigniaPeriod.cs @@ -14,10 +14,12 @@ namespace BMA.EHR.Domain.Models.Insignias public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } [MaxLength(50)] - public string Amount { get; set; } + public int Amount { get; set; } [MaxLength(10)] public string Type { get; set; } public Document? ReliefDoc { get; set; } + [Comment("ราบการยื่นขอ")] + public int Round { get; set; } = 1; [Comment("สถานะการใช้งาน")] public bool IsActive { get; set; } = true; public virtual List InsigniaRequests { get; set; } diff --git a/BMA.EHR.Domain/Models/Insignias/InsigniaRequestProfile.cs b/BMA.EHR.Domain/Models/Insignias/InsigniaRequestProfile.cs index 29c92e70..e0669ddf 100644 --- a/BMA.EHR.Domain/Models/Insignias/InsigniaRequestProfile.cs +++ b/BMA.EHR.Domain/Models/Insignias/InsigniaRequestProfile.cs @@ -31,6 +31,9 @@ namespace BMA.EHR.Domain.Models.Insignias [Column(TypeName = "text")] public string? MatchingConditions { get; set; } + [Comment("สถานะตำแหน่งที่ยื่นขอ")] + public string Status { get; set; } = "PENDING"; + public Profile Profile { get; set; } public Insignia RequestInsignia { get; set; } diff --git a/BMA.EHR.Domain/Shared/GlobalMessages.cs b/BMA.EHR.Domain/Shared/GlobalMessages.cs index 50aaa3db..c8085637 100644 --- a/BMA.EHR.Domain/Shared/GlobalMessages.cs +++ b/BMA.EHR.Domain/Shared/GlobalMessages.cs @@ -74,6 +74,7 @@ #endregion #region " Insignia " + public static readonly string InsigniaDupicate = "มีการยื่นรอบรอบนี้ในปีนี้ไว้อยู่แล้ว"; public static readonly string InsigniaRequestNotFound = "ไม่พบข้อมูลการยื่นขอพระราชทานเครื่องราชย์ของหน่วยงานที่ระบุ!!"; public static readonly string InsigniaPeriodNotFound = "ไม่พบรอบการยื่นขอพระราชทานเครื่องราชย์อิสริยาภรณ์"; public static readonly string CoinPeriodNotFound = "ไม่พบรอบการขอพระราชทานเหรียญจักรพรรดิมาลาที่ระบุ!!"; diff --git a/BMA.EHR.Insignia.Service/Controllers/InsigniaPeriodController.cs b/BMA.EHR.Insignia.Service/Controllers/InsigniaPeriodController.cs index 5d37af6b..7f2eb329 100644 --- a/BMA.EHR.Insignia.Service/Controllers/InsigniaPeriodController.cs +++ b/BMA.EHR.Insignia.Service/Controllers/InsigniaPeriodController.cs @@ -65,6 +65,7 @@ namespace BMA.EHR.Insignia.Service.Controllers period_id = p.Id, period_amount = p.Amount, period_name = p.Name, + period_round = p.Round, period_start = p.StartDate, period_end = p.EndDate, period_status = _repository.CalStatusByDate(p.StartDate, p.EndDate, p.Year.ToString()), @@ -81,6 +82,7 @@ namespace BMA.EHR.Insignia.Service.Controllers period_id = insigniaPeriod.period_id, period_amount = insigniaPeriod.period_amount, period_name = insigniaPeriod.period_name, + period_round = insigniaPeriod.period_round, period_start = insigniaPeriod.period_start, period_end = insigniaPeriod.period_end, period_status = insigniaPeriod.period_status, @@ -113,6 +115,7 @@ namespace BMA.EHR.Insignia.Service.Controllers period_id = p.Id, period_amount = p.Amount, period_name = p.Name, + period_round = p.Round, period_start = p.StartDate, period_end = p.EndDate, period_status = _repository.CalStatusByDate(p.StartDate, p.EndDate, p.Year.ToString()), @@ -129,6 +132,7 @@ namespace BMA.EHR.Insignia.Service.Controllers period_id = data.period_id, period_amount = data.period_amount, period_name = data.period_name, + period_round = data.period_round, period_start = data.period_start, period_end = data.period_end, period_status = data.period_status, @@ -144,6 +148,7 @@ namespace BMA.EHR.Insignia.Service.Controllers /// สร้างรอบเครื่องราช /// /// ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ) + /// รอบที่ /// ชื่อรอบ /// ปีที่เสนอ /// วันที่เริ่มต้น @@ -158,13 +163,20 @@ namespace BMA.EHR.Insignia.Service.Controllers [HttpPost("{type}")] public async Task> Post([FromForm] InsigniaPeriodRequest req, string type) { + var insigniaPeriod = await _context.InsigniaPeriods.AsQueryable() + .Where(x => x.Round == req.Round && x.Year == req.Year) + .FirstOrDefaultAsync(); + if (insigniaPeriod != null) + return Error(GlobalMessages.InsigniaDupicate); + var period = new InsigniaPeriod { - Name = Request.Form.ContainsKey("Name") ? Request.Form["Name"] : "", - Year = Request.Form.ContainsKey("Year") ? Int32.Parse(Request.Form["Year"]) : DateTime.Now.Year, - StartDate = Request.Form.ContainsKey("StartDate") ? DateTime.Parse(Request.Form["StartDate"]) : DateTime.Now, - EndDate = Request.Form.ContainsKey("EndDate") ? DateTime.Parse(Request.Form["EndDate"]) : DateTime.Now, - Amount = Request.Form.ContainsKey("Amount") ? Request.Form["Amount"] : "", + Round = req.Round, + Name = req.Name, + Year = req.Year, + StartDate = req.StartDate, + EndDate = req.EndDate, + Amount = req.Amount, Type = type.Trim().ToUpper(), IsActive = true, CreatedUserId = FullName ?? "", @@ -221,6 +233,7 @@ namespace BMA.EHR.Insignia.Service.Controllers /// แก้ไขรอบเครื่องราช /// /// Id เครื่องราช + /// รอบที่ /// ชื่อรอบ /// ปีที่เสนอ /// วันที่เริ่มต้น @@ -238,6 +251,12 @@ namespace BMA.EHR.Insignia.Service.Controllers if (req == null) return BadRequest(); + var insigniaPeriod = await _context.InsigniaPeriods.AsQueryable() + .Where(x => x.Round == req.Round && x.Year == req.Year && x.Id != id) + .FirstOrDefaultAsync(); + if (insigniaPeriod != null) + return Error(GlobalMessages.InsigniaDupicate); + var uppdated = await _context.InsigniaPeriods.AsQueryable() .Include(x => x.ReliefDoc) .FirstOrDefaultAsync(x => x.Id == id); @@ -245,11 +264,12 @@ namespace BMA.EHR.Insignia.Service.Controllers if (uppdated == null) return NotFound(); - uppdated.Name = Request.Form.ContainsKey("Name") ? Request.Form["Name"] : ""; - uppdated.Year = Request.Form.ContainsKey("Year") ? Int32.Parse(Request.Form["Year"]) : DateTime.Now.Year; - uppdated.StartDate = Request.Form.ContainsKey("StartDate") ? DateTime.Parse(Request.Form["StartDate"]) : DateTime.Now; - uppdated.EndDate = Request.Form.ContainsKey("EndDate") ? DateTime.Parse(Request.Form["EndDate"]) : DateTime.Now; - uppdated.Amount = Request.Form.ContainsKey("Amount") ? Request.Form["Amount"] : ""; + uppdated.Round = req.Round; + uppdated.Name = req.Name; + uppdated.Year = req.Year; + uppdated.StartDate = req.StartDate; + uppdated.EndDate = req.EndDate; + uppdated.Amount = req.Amount; uppdated.LastUpdateFullName = FullName ?? "System Administrator"; uppdated.LastUpdateUserId = UserId ?? ""; uppdated.LastUpdatedAt = DateTime.Now; diff --git a/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs b/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs index 51990b87..ba87b45f 100644 --- a/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs +++ b/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs @@ -38,6 +38,14 @@ namespace BMA.EHR.Insignia.Service.Controllers _httpContextAccessor = httpContextAccessor; } + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + + #endregion + #region " Private " private static string GetRequestlStatusText(string status) @@ -60,20 +68,20 @@ namespace BMA.EHR.Insignia.Service.Controllers #endregion #region " ดึงเครื่องราชฯ ล่าสุดของครู (GetInsigniaLast) " - private InsigniaItem GetInsigniaLast(Guid? id) - { - var insignia = _context.Insignias.AsQueryable() - .Where(i => id != null ? i.Id == id : i.Name.Contains("ตริตาภรณ์มงกุฎไทย")).Select(i => new InsigniaItem - { - Id = i.Id, - Name = i.Name, - ShortName = i.ShortName, - Level = i.InsigniaType == null ? null : i.InsigniaType.Name, - LevelId = i.InsigniaType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : i.InsigniaType.Id - }).FirstOrDefault(); + // private InsigniaItem GetInsigniaLast(Guid? id) + // { + // var insignia = _context.Insignias.AsQueryable() + // .Where(i => id != null ? i.Id == id : i.Name.Contains("ตริตาภรณ์มงกุฎไทย")).Select(i => new InsigniaItem + // { + // Id = i.Id, + // Name = i.Name, + // ShortName = i.ShortName, + // Level = i.InsigniaType == null ? null : i.InsigniaType.Name, + // LevelId = i.InsigniaType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : i.InsigniaType.Id + // }).FirstOrDefault(); - return insignia; - } + // return insignia; + // } #endregion #region " จัดทำรายชื่อครูที่มีสิทธิในการยืนขอเครื่องราชฯ " @@ -240,10 +248,36 @@ namespace BMA.EHR.Insignia.Service.Controllers // return Success(); // } - [HttpGet("{id:length(36)}/{role}/{ocId:length(36)}")] - public async Task> GetInsignaiRequestBkk(Guid id, Guid ocId, string role) + /// + /// list รายการคำขอเครื่องราช ผู้ได้รับ,คนไม่ยื่น,คนที่ถูกลบ + /// + /// Id รอบเครื่องราช + /// Id สังกัด + /// ชื่อตำแหน่งระหว่างสกจ กับ เขต (ตอนนี้ให้ส่ง officer ก่อน) + /// pending=ผู้ได้รับ, reject=คนไม่ยื่น, delete=คนที่ถูกลบ + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("{insigniaPeriodId:length(36)}/{role}/{status}")] + public async Task> GetInsignaiRequestBkk(Guid insigniaPeriodId, Guid ocId, string role, string status) { - var result = await _repository.GetInsigniaRequest(id, ocId); + // var profile = await _context.Profiles.AsQueryable() + // .FirstOrDefaultAsync(x => x.KeycloakId == (UserId != null && UserId != "" ? Guid.Parse(UserId) : Guid.Parse("00000000-0000-0000-0000-000000000000"))); + // if (profile == null) + // return Error(GlobalMessages.DataNotFound); + // var organizationAgencyId = await _context.ProfilePositions.AsQueryable() + // .Where(x => x.Profile == profile) + // .Where(x => x.OrganizationPosition != null) + // .Where(x => x.OrganizationPosition.Organization != null) + // .Where(x => x.OrganizationPosition.Organization.OrganizationAgencyId != null) + // .Select(x => x.OrganizationPosition.Organization.OrganizationAgencyId) + // .FirstOrDefaultAsync(); + // if (organizationAgencyId == null) + // return Error(GlobalMessages.OrganizationNotFound); + // var ocId = organizationAgencyId.Value; + var result = await _repository.GetInsigniaRequest(insigniaPeriodId, ocId); if (result != null) { Guid period = result.PeriodId; @@ -266,138 +300,139 @@ namespace BMA.EHR.Insignia.Service.Controllers // บันทึกรายชื่อ await _repository.InsertCandidate(period, ocId, candidate); } - if (role == "officer") + if (role.Trim().ToUpper() == "OFFICER") { - resend.Items = await _repository.InsigniaHasProfile(period, ocId); + resend.Items = await _repository.InsigniaHasProfile(period, ocId, status); return Success(resend); } else { - var passData = _context.InsigniaRequests.AsQueryable() - .Include(x => x.Organization) - .Include(x => x.RequestProfiles) - .Where(x => x.Organization.Id == ocId) - .Where(x => x.Period.Id == period) - .Select(ir => new - { - requstID = ir.Id, - requstStatus = ir.RequestStatus, - requstStatusName = GetRequestlStatusText(ir.RequestStatus), - fkInstituteId = -1, - // fkDivisionId = ir.Organization.Id, - // fkDivision = ir.Organization.Name, - fkInstitute = "", - fkPeriodId = ir.Period.Id, - insigniaRequestHasProfile = ir.RequestProfiles.AsQueryable() - .Include(x => x.Profile) - .ThenInclude(x => x.Position) - .Include(x => x.Profile) - // .ThenInclude(x => x.PositionNumber) - .Include(x => x.Profile) - // .ThenInclude(x => x.AcademicStanding) - .Include(x => x.RequestInsignia) - .ThenInclude(x => x.InsigniaType) - .Select(irp => new - { - request_id = irp.Request.Id, - isApprove = irp.IsApprove, - statusInstitute = irp.IsApprove.ToString(), - request_date = irp.RequestDate, - profileId = irp.Profile.Id, - // prefix = irp.Profile.Prefix, - firstname = irp.Profile.FirstName, - lastname = irp.Profile.LastName, - // posno = irp.Profile.PositionNumber.Id, - type = irp.Profile.ProfileType, - // position = irp.Profile.Position.Name, - // rank = $"{irp.Profile.PositionType.Name}/{irp.Profile.PositionLevel.Name}", - instituteName = "", - instituteId = -1, - // divisionName = irp.Profile.OrganizationOrganization.Name, - // divisionId = irp.Profile.OrganizationOrganization.Id, - lastInsigniaName = "", - requestInsigniaLevel = irp.RequestInsignia.InsigniaType.Name, - requestInsigniaName = irp.RequestInsignia.Name, - requestQua = irp.QualificationStatus, - requestDoc = irp.DocumentStatus, - requestNote = irp.Note, - requestSalary = irp.Salary, - matchingConditions = JsonConvert.DeserializeObject>(irp.MatchingConditions) - }) - .Where(x => x.isApprove) - .OrderBy(y => y.profileId) - .ToList() - }) - .ToList() - .FirstOrDefault(); + // var passData = _context.InsigniaRequests.AsQueryable() + // .Include(x => x.Organization) + // .Include(x => x.RequestProfiles) + // .Where(x => x.Organization.Id == ocId) + // .Where(x => x.Period.Id == period) + // .Select(ir => new + // { + // requstID = ir.Id, + // requstStatus = ir.RequestStatus, + // requstStatusName = GetRequestlStatusText(ir.RequestStatus), + // fkInstituteId = -1, + // // fkDivisionId = ir.Organization.Id, + // // fkDivision = ir.Organization.Name, + // fkInstitute = "", + // fkPeriodId = ir.Period.Id, + // insigniaRequestHasProfile = ir.RequestProfiles.AsQueryable() + // .Include(x => x.Profile) + // .ThenInclude(x => x.Position) + // .Include(x => x.Profile) + // // .ThenInclude(x => x.PositionNumber) + // .Include(x => x.Profile) + // // .ThenInclude(x => x.AcademicStanding) + // .Include(x => x.RequestInsignia) + // .ThenInclude(x => x.InsigniaType) + // .Select(irp => new + // { + // request_id = irp.Request.Id, + // isApprove = irp.IsApprove, + // statusInstitute = irp.IsApprove.ToString(), + // request_date = irp.RequestDate, + // profileId = irp.Profile.Id, + // // prefix = irp.Profile.Prefix, + // firstname = irp.Profile.FirstName, + // lastname = irp.Profile.LastName, + // // posno = irp.Profile.PositionNumber.Id, + // type = irp.Profile.ProfileType, + // // position = irp.Profile.Position.Name, + // // rank = $"{irp.Profile.PositionType.Name}/{irp.Profile.PositionLevel.Name}", + // instituteName = "", + // instituteId = -1, + // // divisionName = irp.Profile.OrganizationOrganization.Name, + // // divisionId = irp.Profile.OrganizationOrganization.Id, + // lastInsigniaName = "", + // requestInsigniaLevel = irp.RequestInsignia.InsigniaType.Name, + // requestInsigniaName = irp.RequestInsignia.Name, + // requestQua = irp.QualificationStatus, + // requestDoc = irp.DocumentStatus, + // requestNote = irp.Note, + // requestSalary = irp.Salary, + // matchingConditions = JsonConvert.DeserializeObject>(irp.MatchingConditions) + // }) + // .Where(x => x.isApprove) + // .OrderBy(y => y.profileId) + // .ToList() + // }) + // .ToList() + // .FirstOrDefault(); - var failData = _context.InsigniaRequests.AsQueryable() - .Include(x => x.Organization) - .Include(x => x.RequestProfiles) - .Where(x => x.Organization.Id == ocId) - .Where(x => x.Period.Id == period) - .Select(ir => new - { - requstID = ir.Id, - requstStatus = ir.RequestStatus, - requstStatusName = GetRequestlStatusText(ir.RequestStatus), - fkInstituteId = -1, - // fkDivisionId = ir.Organization.Id, - // fkDivision = ir.Organization.Name, - fkInstitute = "", - fkPeriodId = ir.Period.Id, - insigniaRequestHasProfile = ir.RequestProfiles.AsQueryable() - .Include(x => x.Profile) - .ThenInclude(x => x.Position) - .Include(x => x.Profile) - // .ThenInclude(x => x.PositionNumber) - .Include(x => x.Profile) - // .ThenInclude(x => x.AcademicStanding) - .Include(x => x.RequestInsignia) - .ThenInclude(x => x.InsigniaType) - .Select(irp => new - { - request_id = irp.Request.Id, - isApprove = irp.IsApprove, - statusInstitute = irp.IsApprove.ToString(), - request_date = irp.RequestDate, - profileId = irp.Profile.Id, - // prefix = irp.Profile.Prefix, - firstname = irp.Profile.FirstName, - lastname = irp.Profile.LastName, - // posno = irp.Profile.PositionNumber.Id, - type = irp.Profile.ProfileType, - // position = irp.Profile.Position.Name, - // rank = irp.Profile.AcademicStanding.Name, - instituteName = "", - instituteId = -1, - // divisionName = irp.Profile.OrganizationOrganization.Name, - // divisionId = irp.Profile.OrganizationOrganization.Id, - lastInsigniaName = "", - requestInsigniaLevel = irp.RequestInsignia.InsigniaType.Name, - requestInsigniaName = irp.RequestInsignia.Name, - requestQua = irp.QualificationStatus, - requestDoc = irp.DocumentStatus, - requestNote = irp.Note, - requestSalary = irp.Salary, - matchingConditions = JsonConvert.DeserializeObject>(irp.MatchingConditions) - }) - .Where(x => !x.isApprove) - .OrderBy(y => y.profileId) - .ToList() - }) - .ToList() - .FirstOrDefault(); + // var failData = _context.InsigniaRequests.AsQueryable() + // .Include(x => x.Organization) + // .Include(x => x.RequestProfiles) + // .Where(x => x.Organization.Id == ocId) + // .Where(x => x.Period.Id == period) + // .Select(ir => new + // { + // requstID = ir.Id, + // requstStatus = ir.RequestStatus, + // requstStatusName = GetRequestlStatusText(ir.RequestStatus), + // fkInstituteId = -1, + // // fkDivisionId = ir.Organization.Id, + // // fkDivision = ir.Organization.Name, + // fkInstitute = "", + // fkPeriodId = ir.Period.Id, + // insigniaRequestHasProfile = ir.RequestProfiles.AsQueryable() + // .Include(x => x.Profile) + // .ThenInclude(x => x.Position) + // .Include(x => x.Profile) + // // .ThenInclude(x => x.PositionNumber) + // .Include(x => x.Profile) + // // .ThenInclude(x => x.AcademicStanding) + // .Include(x => x.RequestInsignia) + // .ThenInclude(x => x.InsigniaType) + // .Select(irp => new + // { + // request_id = irp.Request.Id, + // isApprove = irp.IsApprove, + // statusInstitute = irp.IsApprove.ToString(), + // request_date = irp.RequestDate, + // profileId = irp.Profile.Id, + // // prefix = irp.Profile.Prefix, + // firstname = irp.Profile.FirstName, + // lastname = irp.Profile.LastName, + // // posno = irp.Profile.PositionNumber.Id, + // type = irp.Profile.ProfileType, + // // position = irp.Profile.Position.Name, + // // rank = irp.Profile.AcademicStanding.Name, + // instituteName = "", + // instituteId = -1, + // // divisionName = irp.Profile.OrganizationOrganization.Name, + // // divisionId = irp.Profile.OrganizationOrganization.Id, + // lastInsigniaName = "", + // requestInsigniaLevel = irp.RequestInsignia.InsigniaType.Name, + // requestInsigniaName = irp.RequestInsignia.Name, + // requestQua = irp.QualificationStatus, + // requestDoc = irp.DocumentStatus, + // requestNote = irp.Note, + // requestSalary = irp.Salary, + // matchingConditions = JsonConvert.DeserializeObject>(irp.MatchingConditions) + // }) + // .Where(x => !x.isApprove) + // .OrderBy(y => y.profileId) + // .ToList() + // }) + // .ToList() + // .FirstOrDefault(); - var period_data = (from p in _context.InsigniaPeriods.AsQueryable() - where p.Id == period - select new - { - periodName = p.Name, - periodYear = p.Year, - }).FirstOrDefault(); + // var period_data = (from p in _context.InsigniaPeriods.AsQueryable() + // where p.Id == period + // select new + // { + // periodName = p.Name, + // periodYear = p.Year, + // }).FirstOrDefault(); - return Success(new { passData = passData, failData = failData, period = period_data }); + // return Success(new { passData = passData, failData = failData, period = period_data }); + return Success(); } // select data to display } @@ -407,102 +442,213 @@ namespace BMA.EHR.Insignia.Service.Controllers #endregion - #region " บันทึกหมายเหตุ " + // #region " บันทึกหมายเหตุ " - [HttpPut("note/{profileId}")] - public async Task> SaveNote(Guid profileId, SaveRequsetNote items) + // [HttpPut("note/{profileId}")] + // public async Task> SaveNote(Guid profileId, SaveRequsetNote items) + // { + // var id = await _repository.GetRequestId(items.PeriodId, items.OcId); + // var note = _context.InsigniaRequestProfiles.AsQueryable() + // .Where(d => d.Profile.Id == profileId && d.Request.Id == id).FirstOrDefault(); + // if (note != null) + // note.Note = items.Note; + // _context.SaveChanges(); + // return Success(); + // } + + // #endregion + + // #region " บันทึกรายชื่อครูในการขอยื่นเครื่องราชฯ เเต่ยังไม่ส่งไปยัง ผอ.โรงเรียน " + + // [HttpPut("approve/{ocId:length(36)}")] + // public async Task> SaveRequestList(Guid id, Guid ocId, InsigniaApproveRequest items) + // { + // var result = await _repository.GetInsigniaRequest(id, ocId); + // if (result != null) + // await _repository.SaveAprove(result.PeriodId, ocId, items); + // return Success(); + // } + + // #endregion + + // #region " เปลี่ยน status เป็น st2 รอ ผอ.สำนักรับรอง " + + // [HttpPost("status/officer/send/{ocId:length(36)}")] + // public async Task> ChangeStatusToSt2(Guid id, Guid ocId, InsigniaApproveRequest items) + // { + // var result = await _repository.GetInsigniaRequest(id, ocId); + + // if (items != null) + // { + // _repository.SaveAprove(result.PeriodId, ocId, items); + // } + // var requestId = await _repository.GetRequestId(result.PeriodId, ocId); + // var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId); + // if (requestNew != null) + // { + // requestNew.RequestStatus = "st2"; + // _context.SaveChanges(); + // return Success(); + // } + // else + // return Error(GlobalMessages.InsigniaRequestNotFound); + // } + + // #endregion + + // #region " เปลี่ยน status สำหรับ ผอ.สำนัก " + + // [HttpPost("status/director/approve/{ocId:length(36)}")] + // public async Task> ChangeStatusToSt5p(Guid id, Guid ocId) + // { + // var result = await _repository.GetInsigniaRequest(id, ocId); + // if (result == null) + // return Error(GlobalMessages.InsigniaRequestNotFound); + // var requestId = await _repository.GetRequestId(result.PeriodId, ocId); + // if (requestId == null) + // return Error(GlobalMessages.InsigniaRequestNotFound); + // var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId); + // if (requestNew != null) + // { + // requestNew.RequestStatus = "st5p"; + // _context.SaveChanges(); + // return Success(); + // } + // else + // return Error(GlobalMessages.InsigniaRequestNotFound); + // } + + // [HttpPost("status/director/reject/{ocId:length(36)}")] + // public async Task> ChangeStatusToSt1(Guid id, Guid ocId) + // { + // var result = await _repository.GetInsigniaRequest(id, ocId); + // if (result == null) + // return Error(GlobalMessages.InsigniaRequestNotFound); + // var requestId = await _repository.GetRequestId(result.PeriodId, ocId); + // if (requestId == null) + // return Error(GlobalMessages.InsigniaRequestNotFound); + // var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId); + // if (requestNew != null) + // { + // requestNew.RequestStatus = "st1"; + // _context.SaveChanges(); + // return Success(); + // } + // else + // return Error(GlobalMessages.InsigniaRequestNotFound); + // } + // #endregion + + /// + /// ย้ายขอมูลไปเป็น คนที่ไม่ยื่นขอ + /// + /// Id ผู้ยื่นขอ + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("status/reject/{profileId:length(36)}")] + public async Task> RejectProfileInsignia(Guid profileId) { - var id = await _repository.GetRequestId(items.PeriodId, items.OcId); - var note = _context.InsigniaRequestProfiles.AsQueryable() - .Where(d => d.Profile.Id == profileId && d.Request.Id == id).FirstOrDefault(); - if (note != null) - note.Note = items.Note; + var profile = await _context.Profiles.AsQueryable() + .FirstOrDefaultAsync(x => x.Id == profileId); + if (profile == null) + return Error(GlobalMessages.DataNotFound); + var insigniaRequestProfile = await _context.InsigniaRequestProfiles.FirstOrDefaultAsync(x => x.Profile == profile); + if (insigniaRequestProfile == null) + return Error(GlobalMessages.InsigniaPeriodNotFound); + insigniaRequestProfile.Status = "REJECT"; _context.SaveChanges(); return Success(); } - #endregion - - #region " บันทึกรายชื่อครูในการขอยื่นเครื่องราชฯ เเต่ยังไม่ส่งไปยัง ผอ.โรงเรียน " - - [HttpPut("approve/{ocId:length(36)}")] - public async Task> SaveRequestList(Guid id, Guid ocId, InsigniaApproveRequest items) + /// + /// ย้ายขอมูลไปเป็น คนที่ถูกลบออก + /// + /// Id ผู้ยื่นขอ + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("status/delete/{profileId:length(36)}")] + public async Task> DeleteProfileInsignia(Guid profileId) { - var result = await _repository.GetInsigniaRequest(id, ocId); - if (result != null) - await _repository.SaveAprove(result.PeriodId, ocId, items); + var profile = await _context.Profiles.AsQueryable() + .FirstOrDefaultAsync(x => x.Id == profileId); + if (profile == null) + return Error(GlobalMessages.DataNotFound); + var insigniaRequestProfile = await _context.InsigniaRequestProfiles.FirstOrDefaultAsync(x => x.Profile == profile); + if (insigniaRequestProfile == null) + return Error(GlobalMessages.InsigniaPeriodNotFound); + insigniaRequestProfile.Status = "DELETE"; + _context.SaveChanges(); return Success(); } - #endregion - - #region " เปลี่ยน status เป็น st2 รอ ผอ.สำนักรับรอง " - - [HttpPost("status/officer/send/{ocId:length(36)}")] - public async Task> ChangeStatusToSt2(Guid id, Guid ocId, InsigniaApproveRequest items) + /// + /// สรุปจำนวนการยื่นขอในแต่ละรอบ + /// + /// Id รอบการยื่นขอ + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("dashboard/{insigniaPeriodId:length(36)}")] + public async Task> DashboardInsigniaPeriod(Guid insigniaPeriodId) { - var result = await _repository.GetInsigniaRequest(id, ocId); - - if (items != null) - { - _repository.SaveAprove(result.PeriodId, ocId, items); - } - var requestId = await _repository.GetRequestId(result.PeriodId, ocId); - var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId); - if (requestNew != null) - { - requestNew.RequestStatus = "st2"; - _context.SaveChanges(); - return Success(); - } - else + var insigniaPeriod = await _context.InsigniaPeriods.FirstOrDefaultAsync(x => x.Id == insigniaPeriodId); + if (insigniaPeriod == null) return Error(GlobalMessages.InsigniaRequestNotFound); + var orgSendCount = await _context.InsigniaRequests + .Where(x => x.Period == insigniaPeriod) + .CountAsync(); + var allUserUser = await _context.InsigniaRequests + .Where(x => x.Period == insigniaPeriod) + .Select(x => x.RequestProfiles.Count()) + .SumAsync(); + var orgAllCount = await _context.Organizations + .Where(x => x.OrganizationType != null) + .Where(x => x.OrganizationType.Name == "หน่วยงาน") + .CountAsync(); + + return Success(new { OrgAllCount = orgAllCount, OrgSendCount = orgSendCount, OrgNoSendCount = orgAllCount - orgSendCount, AllUserUser = allUserUser }); } - #endregion - - #region " เปลี่ยน status สำหรับ ผอ.สำนัก " - - [HttpPost("status/director/approve/{ocId:length(36)}")] - public async Task> ChangeStatusToSt5p(Guid id, Guid ocId) + /// + /// หน่วยงานทียังไม่ส่งรายชื่อ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("org/no-send/{insigniaPeriodId:length(36)}")] + public async Task> ListOrgDontSentUser(Guid insigniaPeriodId) { - var result = await _repository.GetInsigniaRequest(id, ocId); - if (result == null) - return Error(GlobalMessages.InsigniaRequestNotFound); - var requestId = await _repository.GetRequestId(result.PeriodId, ocId); - if (requestId == null) - return Error(GlobalMessages.InsigniaRequestNotFound); - var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId); - if (requestNew != null) - { - requestNew.RequestStatus = "st5p"; - _context.SaveChanges(); - return Success(); - } - else + var insigniaPeriod = await _context.InsigniaPeriods.FirstOrDefaultAsync(x => x.Id == insigniaPeriodId); + if (insigniaPeriod == null) return Error(GlobalMessages.InsigniaRequestNotFound); + var orgIdSend = await _context.InsigniaRequests + .Where(x => x.Period == insigniaPeriod) + .Select(x => x.Organization.Id) + .ToListAsync(); + var orgAllCount = await _context.Organizations + .Where(x => x.OrganizationOrganization != null) + .Where(x => x.OrganizationType != null) + .Where(x => x.OrganizationType.Name == "หน่วยงาน") + .Where(x => !orgIdSend.Contains(x.Id)) + .Select(x => new + { + OrgId = x.Id, + OrgName = x.OrganizationOrganization.Name + }) + .ToListAsync(); + + return Success(); } - [HttpPost("status/director/reject/{ocId:length(36)}")] - public async Task> ChangeStatusToSt1(Guid id, Guid ocId) - { - var result = await _repository.GetInsigniaRequest(id, ocId); - if (result == null) - return Error(GlobalMessages.InsigniaRequestNotFound); - var requestId = await _repository.GetRequestId(result.PeriodId, ocId); - if (requestId == null) - return Error(GlobalMessages.InsigniaRequestNotFound); - var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId); - if (requestNew != null) - { - requestNew.RequestStatus = "st1"; - _context.SaveChanges(); - return Success(); - } - else - return Error(GlobalMessages.InsigniaRequestNotFound); - } - - #endregion } }