Merge branch 'develop' into dev

* develop:
  add api post
  filter ตามวันที่ประกาศ
  fix #1911, #1931
This commit is contained in:
Warunee Tamkoo 2025-11-07 09:34:50 +07:00
commit 3b5621033a
2 changed files with 128 additions and 40 deletions

View file

@ -2067,7 +2067,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
// ---------------------------
dynamic header = null;
int _count = await _context.Recruits.Where(x => x.RecruitImport.Id == id).CountAsync();
if (data.Count > 0)
if (_count > 0)
{
header = await _context.RecruitScores
.Include(x => x.ScoreImport)
@ -2238,7 +2238,8 @@ namespace BMA.EHR.Recruit.Service.Controllers
var this_year = DateTime.Now.Year.ToCeYear();
var periods = (from r in _context.RecruitImports.AsQueryable().Include(x => x.RecruitImages)
where r.Year == this_year
where (r.AnnouncementStartDate != null && r.AnnouncementStartDate.Value.Year == this_year) ||
(r.AnnouncementEndDate != null && r.AnnouncementEndDate.Value.Year == this_year)
orderby r.AnnouncementStartDate descending
select new
{
@ -2260,31 +2261,6 @@ namespace BMA.EHR.Recruit.Service.Controllers
.ToList();
//var periods = _context.RecruitImports.AsQueryable()
// .Where(x => x.Year == this_year)
// .Include(x => x.RecruitImages)
// .Select(r => new
// {
// id = r.Id,
// title = $"{r.Name} ครั้งที่ {r.Order}/{r.Year.ToThaiYear()}",
// category = "สำนักงาน ก.ก.",
// category_id = 1,
// announcement_startDate = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-mm-dd"),
// announcement_endDate = r.AnnouncementEndDate == null ? "" : r.AnnouncementEndDate.Value.ToString("yyyy-MM-dd"),
// announcementExam = true,
// register_startDate = r.RegisterStartDate == null ? "" : r.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
// register_endDate = r.RegisterEndDate == null ? "" : r.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
// payment_startDate = r.PaymentStartDate == null ? "" : r.PaymentStartDate.Value.ToString("yyyy-MM-dd"),
// payment_endDate = r.PaymentEndDate == null ? "" : r.PaymentEndDate.Value.ToString("yyyy-MM-dd"),
// exam_date = r.ExamDate == null ? "" : r.ExamDate.Value.ToString("yyyy-MM-dd"),
// image = r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault() == null ? "" :
// r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault().Document.Id.ToString("D")
// })
// .OrderByDescending(x => x.announcement_startDate)
// .ToList();
if (limit > 0)
periods = periods.Take(limit).ToList();
@ -2318,6 +2294,95 @@ namespace BMA.EHR.Recruit.Service.Controllers
}
}
/// <summary>
/// ดึงรายการรอบการสอบแข่งขันสำหรับ CMS (POST version)
/// </summary>
/// <param name="request">ข้อมูลการกรองตามช่วงวันที่</param>
/// <returns>รายการรอบการสอบแข่งขัน</returns>
/// <response code="200">เมื่อดึงข้อมูลสำเร็จ</response>
/// <response code="400">ข้อมูลที่ส่งมาไม่ถูกต้อง</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("competitive")]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetPeriodForCMSPost([FromBody] CompetitivePeriodRequest request)
{
try
{
if (request == null)
return BadRequest("Request body is required");
var query = _context.RecruitImports.AsQueryable();
// กรองตามช่วงวันที่ (ถ้ามีการส่งมา)
if (request.StartDate.HasValue && request.EndDate.HasValue)
{
var startDate = request.StartDate.Value.Date;
var endDate = request.EndDate.Value.Date.AddDays(1).AddTicks(-1); // ถึงสิ้นวัน
query = query.Where(r =>
(r.AnnouncementStartDate != null && r.AnnouncementStartDate.Value >= startDate && r.AnnouncementStartDate.Value <= endDate) ||
(r.AnnouncementEndDate != null && r.AnnouncementEndDate.Value >= startDate && r.AnnouncementEndDate.Value <= endDate) ||
(r.AnnouncementStartDate != null && r.AnnouncementEndDate != null &&
r.AnnouncementStartDate.Value <= endDate && r.AnnouncementEndDate.Value >= startDate)
);
}
var periods = (from r in query.Include(x => x.RecruitImages)
orderby r.AnnouncementStartDate descending
select new
{
id = r.Id,
title = $"{r.Name} ครั้งที่ {r.Order}/{r.Year.ToThaiYear()}",
category = "สำนักงาน ก.ก.",
category_id = 1,
announcement_startDate = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-MM-dd"),
announcement_endDate = r.AnnouncementEndDate == null ? "" : r.AnnouncementEndDate.Value.ToString("yyyy-MM-dd"),
announcementExam = true,
register_startDate = r.RegisterStartDate == null ? "" : r.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
register_endDate = r.RegisterEndDate == null ? "" : r.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
payment_startDate = r.PaymentStartDate == null ? "" : r.PaymentStartDate.Value.ToString("yyyy-MM-dd"),
payment_endDate = r.PaymentEndDate == null ? "" : r.PaymentEndDate.Value.ToString("yyyy-MM-dd"),
exam_date = r.ExamDate == null ? "" : r.ExamDate.Value.ToString("yyyy-MM-dd"),
image = r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault() == null ? "" :
r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault().Document.Id.ToString("D")
})
.ToList();
if (request.Limit > 0)
periods = periods.Take(request.Limit).ToList();
var result = new List<dynamic>();
foreach (var p in periods)
{
result.Add(new
{
p.id,
p.title,
p.category,
p.category_id,
p.announcementExam,
p.announcement_startDate,
p.announcement_endDate,
p.register_endDate,
p.register_startDate,
p.payment_startDate,
p.payment_endDate,
p.exam_date,
image = p.image == "" ? "" : _minioService.GetFilePath(Guid.Parse(p.image)).Result,
});
}
return Ok(result);
}
catch (Exception ex)
{
return StatusCode(500, ex.Message);
}
}
[HttpGet("competitive/{id:length(36)}")]
[AllowAnonymous]
public IActionResult GetPeriodForCMSById(Guid id)
@ -2692,12 +2757,12 @@ namespace BMA.EHR.Recruit.Service.Controllers
{
var examInfo = new ExamInfo
{
PositionName = reader["Position_name"].ToString(),
PositionLevel = reader["position_level"].ToString(),
PositionType = reader["position_type"].ToString(),
Gender = reader["Gender"].ToString(),
Age = DateTimeExtension.CalculateAge(Convert.ToDateTime(reader["Dateofbirth"]), 0, 0),
Degree = reader["Degree"].ToString(),
PositionName = reader["Position_name"]?.ToString() ?? "",
PositionLevel = reader["position_level"]?.ToString() ?? "",
PositionType = reader["position_type"]?.ToString() ?? "",
Gender = reader["Gender"]?.ToString() ?? "",
Age = reader["Dateofbirth"] != DBNull.Value ? DateTimeExtension.CalculateAge(Convert.ToDateTime(reader["Dateofbirth"]), 0, 0) : 0,
Degree = reader["Degree"]?.ToString() ?? "",
};
header.Add(examInfo);
@ -2788,13 +2853,13 @@ namespace BMA.EHR.Recruit.Service.Controllers
{
var examInfo = new ExamInfo
{
PositionName = reader["Position_name"].ToString(),
PositionLevel = reader["position_level"].ToString(),
PositionType = reader["position_type"].ToString(),
Gender = reader["Gender"].ToString(),
Age = DateTimeExtension.CalculateAge(Convert.ToDateTime(reader["Dateofbirth"]), 0, 0),
Degree = reader["Degree"].ToString(),
Result = reader["Result"].ToString()
PositionName = reader["Position_name"]?.ToString() ?? "",
PositionLevel = reader["position_level"]?.ToString() ?? "",
PositionType = reader["position_type"]?.ToString() ?? "",
Gender = reader["Gender"]?.ToString() ?? "",
Age = reader["Dateofbirth"] != DBNull.Value ? DateTimeExtension.CalculateAge(Convert.ToDateTime(reader["Dateofbirth"]), 0, 0) : 0,
Degree = reader["Degree"]?.ToString() ?? "",
Result = reader["Result"]?.ToString() ?? ""
};
header.Add(examInfo);

View file

@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations;
namespace BMA.EHR.Recruit.Service.Requests.Recruits
{
public class CompetitivePeriodRequest
{
/// <summary>
/// วันที่เริ่มต้นของช่วงที่ต้องการกรอง
/// </summary>
public DateTime? StartDate { get; set; }
/// <summary>
/// วันที่สิ้นสุดของช่วงที่ต้องการกรอง
/// </summary>
public DateTime? EndDate { get; set; }
/// <summary>
/// จำนวนรายการสูงสุดที่ต้องการ (0 = ไม่จำกัด)
/// </summary>
[Range(0, int.MaxValue, ErrorMessage = "Limit ต้องมากกว่าหรือเท่ากับ 0")]
public int Limit { get; set; } = 0;
}
}