2584 lines
No EOL
137 KiB
C#
2584 lines
No EOL
137 KiB
C#
using Amazon.S3.Model;
|
|
using BMA.EHR.MetaData.Service.Models;
|
|
using BMA.EHR.Profile.Service.Models.HR;
|
|
using BMA.EHR.Recruit.Service.Core;
|
|
using BMA.EHR.Recruit.Service.Data;
|
|
using BMA.EHR.Recruit.Service.Extensions;
|
|
using BMA.EHR.Recruit.Service.Models.Recruits;
|
|
using BMA.EHR.Recruit.Service.Requests.Recruits;
|
|
using BMA.EHR.Recruit.Service.Responses;
|
|
using BMA.EHR.Recruit.Service.Services;
|
|
using BMA.EHR.Recurit.Service.Data;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using MySqlConnector;
|
|
using MySqlX.XDevAPI.Common;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using OfficeOpenXml;
|
|
using Org.BouncyCastle.Ocsp;
|
|
using Sentry;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using System.Data;
|
|
using System.Net;
|
|
using System.Net.Http.Headers;
|
|
using System.Net.WebSockets;
|
|
using System.Security.Claims;
|
|
using System.Text;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
using System.Globalization;
|
|
|
|
namespace BMA.EHR.Recruit.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/recruit")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("จัดการข้อมูลการสอบแข่งขัน")]
|
|
public class RecruitController : BaseController
|
|
{
|
|
#region " Fields "
|
|
|
|
private readonly ApplicationDbContext _context;
|
|
private readonly MetadataDbContext _contextMetadata;
|
|
private readonly MinIOService _minioService;
|
|
private readonly IWebHostEnvironment _webHostEnvironment;
|
|
private readonly RecruitService _recruitService;
|
|
private readonly PermissionRepository _permission;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly ILogger<RecruitController> _logger;
|
|
private readonly IConfiguration _configuration;
|
|
//private readonly DateTimeExtension;
|
|
|
|
#endregion
|
|
|
|
#region " Constructor and Destructor "
|
|
|
|
public RecruitController(ApplicationDbContext context,
|
|
MetadataDbContext contextMetadata,
|
|
MinIOService minioService,
|
|
IWebHostEnvironment webHostEnvironment,
|
|
RecruitService recruitService,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
ILogger<RecruitController> logger,
|
|
IConfiguration configuration,
|
|
PermissionRepository permission
|
|
//DateTimeExtension extensions
|
|
)
|
|
{
|
|
_context = context;
|
|
_contextMetadata = contextMetadata;
|
|
_minioService = minioService;
|
|
_webHostEnvironment = webHostEnvironment;
|
|
_recruitService = recruitService;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_configuration = configuration;
|
|
_logger = logger;
|
|
_permission = permission;
|
|
//_extensions = extensions;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Properties "
|
|
|
|
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
|
|
|
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
|
private string? token => _httpContextAccessor.HttpContext.Request.Headers["Authorization"];
|
|
|
|
#endregion
|
|
|
|
#region " Methods "
|
|
|
|
#region " Private "
|
|
|
|
private int GetColumnIndex(string[] columns, string name, bool partial = false)
|
|
{
|
|
try
|
|
{
|
|
if (partial)
|
|
return Array.FindIndex(columns, x => x.Contains(name)) + 1;
|
|
else
|
|
return Array.FindIndex(columns, x => x == name) + 1;
|
|
}
|
|
catch
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
private string CalculateDiff(DateTime d1, DateTime d2)
|
|
{
|
|
if (d1 > d2) return "ข้อมูลไม่ถูกต้อง";
|
|
|
|
TimeSpan sp = d2.Subtract(d1);
|
|
int yy = sp.Days / 365;
|
|
int mm = (sp.Days - (yy * 365)) / 30;
|
|
int dd = (sp.Days - (yy * 365) - (mm * 30));
|
|
|
|
var sb = new StringBuilder();
|
|
sb.Clear();
|
|
sb.Append(yy == 0 ? "" : $"{yy} ปี ");
|
|
sb.Append(mm == 0 ? "" : $"{mm} เดือน ");
|
|
//sb.Append(dd == 0 ? "" : $"{dd} วัน ");
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
private async Task<int> GetExamCount(Guid exam)
|
|
{
|
|
try
|
|
{
|
|
return await _context.RecruitPayments.AsQueryable()
|
|
.Include(x => x.Recruit)
|
|
.ThenInclude(x => x.RecruitImport)
|
|
.Where(x => x.Recruit.RecruitImport.Id == exam)
|
|
.CountAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private async Task<int> GetPassExamCount(Guid exam)
|
|
{
|
|
try
|
|
{
|
|
return await _context.RecruitScores.AsQueryable()
|
|
.Include(x => x.ScoreImport)
|
|
.Where(x => x.ScoreImport.Id == exam)
|
|
.Where(x => x.ExamStatus == "ผ่าน")
|
|
.CountAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private async Task<int> GetScoreCount(Guid exam)
|
|
{
|
|
try
|
|
{
|
|
return await _context.RecruitScores.AsQueryable()
|
|
.Include(x => x.ScoreImport)
|
|
.Where(x => x.ScoreImport.Id == exam)
|
|
.CountAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private class ExamInfo
|
|
{
|
|
public string PositionName { get; set; }
|
|
public string PositionLevel { get; set; }
|
|
public string PositionType { get; set; }
|
|
public string Gender { get; set; }
|
|
public int Age { get; set; }
|
|
public string Degree { get; set; }
|
|
public string Result { get; set; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Ex. Upload, Download and Delete file "
|
|
|
|
/// <summary>
|
|
/// ตัวอย่างในการเขียน api เพื่อทำการ upload file
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการ upload สำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("upload"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
[AllowAnonymous]
|
|
public async Task<ActionResult<ResponseObject>> UploadFile()
|
|
{
|
|
try
|
|
{
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
|
|
var file = Request.Form.Files[0];
|
|
var doc = await _minioService.UploadFileAsync(file);
|
|
|
|
return Success(doc);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ตัวอย่างในการเขียน api เพื่อทำการ delete file
|
|
/// </summary>
|
|
/// <param name="id">รหัสไฟล์ในฐานข้อมูล</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการ delete file สำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("delete/{id:length(36)}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
[AllowAnonymous]
|
|
public async Task<ActionResult<ResponseObject>> DeleteFile(Guid id)
|
|
{
|
|
try
|
|
{
|
|
await _minioService.DeleteFileAsync(id);
|
|
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ตัวอย่างในการเขียน api เพื่อทำการ download file
|
|
/// </summary>
|
|
/// <param name="id">รหัสไฟล์ในฐานข้อมูล</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการ download file สำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("download/{id:length(36)}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
[AllowAnonymous]
|
|
public async Task<ActionResult<ResponseObject>> DownloadFile(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var file_data = await _minioService.DownloadFileAsync(id);
|
|
|
|
Response.Headers["Content-Disposition"] = $"inline; filename={file_data.FileName}";
|
|
|
|
var ret = new FileContentResult(file_data.FileContent, file_data.FileType)
|
|
{
|
|
FileDownloadName = file_data.FileName
|
|
};
|
|
|
|
return ret;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region " จัดการรอบการสมัครสอบแข่งขัน "
|
|
|
|
/// <summary>
|
|
/// แสดงข้อมูลรอบการสอบแข่งขัน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("period")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetPeriodsAsync()
|
|
{
|
|
try
|
|
{
|
|
var data = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.ImportFile)
|
|
.Include(x => x.Recruits)
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.ImportFile)
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.Scores)
|
|
.OrderByDescending(x => x.Year)
|
|
.ThenByDescending(x => x.Order)
|
|
.Select(x => new
|
|
{
|
|
x.Id,
|
|
x.Year,
|
|
x.Name,
|
|
x.Order,
|
|
ImportDate = x.CreatedAt.Date.ToThaiShortDate(),
|
|
ExamCount = x.Recruits.Count(),
|
|
Score = x.ScoreImport == null ? null :
|
|
new
|
|
{
|
|
ID = x.ScoreImport.Id,
|
|
ImportYear = x.ScoreImport.Year,
|
|
ImportDate = x.CreatedAt.Date.ToThaiShortDate(),
|
|
ScoreCount = x.ScoreImport.Scores.Count(),
|
|
|
|
}
|
|
})
|
|
.ToListAsync();
|
|
|
|
return Success(data);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// แสดงข้อมูลรอบการสอบแข่งขันเป็นรายการ
|
|
/// </summary>
|
|
/// <param name="id">รหัสรอบการสอบแข่งขัน</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("period/{id:length(36)}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetPeriodByIdAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var data = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.RecruitImages)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.RecruitDocuments)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.ImportFile)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Addresses)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Occupations)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Certificates)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Educations)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Payments)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Documents)
|
|
.ThenInclude(x => x.DocumentFile)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
var new_image = new List<dynamic>();
|
|
foreach (var p in data.RecruitImages)
|
|
{
|
|
new_image.Add(new
|
|
{
|
|
p.Id,
|
|
p.Document.FileName,
|
|
p.Document.FileSize,
|
|
p.Document.FileType,
|
|
detail = _minioService.GetFilePath(p.Document.Id).Result,
|
|
});
|
|
}
|
|
|
|
// re create doc list
|
|
var new_doc = new List<dynamic>();
|
|
foreach (var p in data.RecruitDocuments)
|
|
{
|
|
new_doc.Add(new
|
|
{
|
|
p.Id,
|
|
p.Document.FileName,
|
|
p.Document.FileSize,
|
|
p.Document.FileType,
|
|
detail = _minioService.GetFilePath(p.Document.Id).Result,
|
|
});
|
|
}
|
|
|
|
return Success(new { periods = data, images = new_image, files = new_doc });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// เพิ่มข้อมูลรอบการจัดสอบแข่งขัน
|
|
/// </summary>
|
|
/// <param name="req">Request parameters</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการเพิ่มข้อมูลสำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("period")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> PostPeriodAsync([FromBody] PostRecruitImportRequest req)
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_EXAM_CONTEST");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
if (req == null)
|
|
return Error(GlobalMessages.InvalidRequestParam, (int)HttpStatusCode.BadRequest);
|
|
|
|
var import = new RecruitImport
|
|
{
|
|
Year = req.Year,
|
|
Name = req.Name,
|
|
Order = req.Order,
|
|
Detail = req.Detail,
|
|
Fee = req.Fee,
|
|
AnnouncementStartDate = req.AnnouncementStartDate,
|
|
AnnouncementEndDate = req.AnnouncementEndDate,
|
|
RegisterStartDate = req.RegisterStartDate,
|
|
RegisterEndDate = req.RegisterEndDate,
|
|
ExamDate = req.ExamDate,
|
|
PaymentStartDate = req.PaymentStartDate,
|
|
PaymentEndDate = req.PaymentEndDate,
|
|
Note = req.Note,
|
|
AnnouncementDate = req.AnnouncementDate,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
};
|
|
await _context.RecruitImports.AddAsync(import);
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success(import);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// แก้ไขข้อมูลรอบการจัดสอบแข่งขัน
|
|
/// </summary>
|
|
/// <param name="id">รหัสรอบการสอบแข่งขัน</param>
|
|
/// <param name="req">Request parameters</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการเพิ่มข้อมูลสำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("period/{id:length(36)}"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> PutPeriodAsync(Guid id, [FromBody] PostRecruitImportRequest req)
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_EXAM_CONTEST");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var data = await _context.RecruitImports.AsQueryable().FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (data == null)
|
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
|
|
|
data.Name = req.Name;
|
|
data.Year = req.Year;
|
|
data.Order = req.Order;
|
|
data.Detail = req.Detail;
|
|
data.Fee = req.Fee;
|
|
data.AnnouncementEndDate = req.AnnouncementEndDate;
|
|
data.AnnouncementStartDate = req.AnnouncementStartDate;
|
|
data.RegisterStartDate = req.RegisterStartDate;
|
|
data.RegisterEndDate = req.RegisterEndDate;
|
|
data.PaymentEndDate = req.PaymentEndDate;
|
|
data.PaymentStartDate = req.PaymentStartDate;
|
|
data.ExamDate = req.ExamDate;
|
|
data.Note = req.Note;
|
|
data.AnnouncementDate = req.AnnouncementDate;
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success(data);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// ลบข้อมูลรอบการจัดสอบแข่งขัน
|
|
/// </summary>
|
|
/// <param name="id">รหัสรอบการสอบแข่งขัน</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการลบข้อมูลสำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpDelete("period/{id:length(36)}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> DeletePeriodAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var data = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.ImportFile)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Addresses)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Occupations)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Certificates)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Educations)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Payments)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Documents)
|
|
.ThenInclude(x => x.DocumentFile)
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.ImportFile)
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.Scores)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
_context.RecruitImports.Remove(data);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Candidate Files "
|
|
|
|
/// <summary>
|
|
/// แสดงข้อมูลสำหรับหน้าจอ รายการนำเข้าข้อมูลผู้สมัครสอบแข่งขัน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อแสดงรายการข้อมูลสำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("candidate")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetCandidateFilesAsync()
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_EXAM_CONTEST");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var data = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.ImportFile)
|
|
.Include(x => x.Recruits)
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.ImportFile)
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.Scores)
|
|
.OrderByDescending(x => x.Year)
|
|
.ThenByDescending(x => x.Order)
|
|
.ThenByDescending(x => x.LastUpdatedAt)
|
|
.Select(x => new
|
|
{
|
|
x.Id,
|
|
x.Year,
|
|
x.Name,
|
|
x.Order,
|
|
ImportDate = x.CreatedAt.Date.ToThaiShortDate(),
|
|
ExamCount = x.Recruits.Count(),
|
|
Score = x.ScoreImport == null || x.ScoreImport.Scores.Count == 0 ? null :
|
|
new
|
|
{
|
|
ID = x.ScoreImport.Id,
|
|
ImportYear = x.ScoreImport.Year,
|
|
ImportDate = x.CreatedAt.Date.ToThaiShortDate(),
|
|
ScoreCount = x.ScoreImport.Scores.Count(),
|
|
ResultCount = x.ScoreImport.Scores.Count(x => !string.IsNullOrEmpty(x.Number))
|
|
},
|
|
x.CreatedUserId,
|
|
})
|
|
.ToListAsync();
|
|
|
|
var roles = _httpContextAccessor?.HttpContext?.User?.FindAll(ClaimTypes.Role)?.Select(c => c.Value).ToList();
|
|
|
|
return Success(data);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// นำเข้ารายชื่อผู้สมัครสอบแข่งขัน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำนำเข้าข้อมูลสำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("candidate"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> ImportCandidateFileAsync([FromForm] PostRecruitImportRequest req)
|
|
{
|
|
var tmpDir = Path.Combine(_webHostEnvironment.ContentRootPath, "tmp");
|
|
if (!Directory.Exists(tmpDir))
|
|
Directory.CreateDirectory(tmpDir);
|
|
|
|
var importFile = Path.Combine(tmpDir, $"c_{DateTime.Now.ToString("ddMMyyyyHHmmss")}.xlsx");
|
|
var import_doc_id = "";
|
|
|
|
try
|
|
{
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
|
|
var file = Request.Form.Files[0];
|
|
var doc = await _minioService.UploadFileAsync(file);
|
|
import_doc_id = doc.Id.ToString("D");
|
|
|
|
var fileContent = (await _minioService.DownloadFileAsync(doc.Id)).FileContent;
|
|
|
|
// สร้างรอบการบรรจุ โดยเอาเข้ามูลมาใส่จาก Request
|
|
var imported = new RecruitImport
|
|
{
|
|
Year = req.Year,
|
|
Order = req.Order,
|
|
Name = req.Name,
|
|
ImportFile = doc,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
ImportHostories = new List<RecruitImportHistory>
|
|
{
|
|
new RecruitImportHistory
|
|
{
|
|
Description = "นำเข้าข้อมูลผู้สมัครสอบแข่งขัน",
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
}
|
|
}
|
|
};
|
|
|
|
await _context.RecruitImports.AddAsync(imported);
|
|
|
|
// import datafile
|
|
System.IO.File.WriteAllBytes(importFile, fileContent);
|
|
|
|
using (var c_package = new ExcelPackage(new FileInfo(importFile)))
|
|
{
|
|
// loop from sheet2 to end
|
|
|
|
for (int i = 0; i < c_package.Workbook.Worksheets.Count; i++)
|
|
{
|
|
var workSheet = c_package.Workbook.Worksheets[i];
|
|
var totalRows = workSheet.Dimension.Rows;
|
|
var cols = workSheet.GetHeaderColumns();
|
|
|
|
int row = 2;
|
|
|
|
while (row <= totalRows)
|
|
{
|
|
var cell1 = workSheet?.Cells[row, 1]?.GetValue<string>();
|
|
if (cell1 == "" || cell1 == null) break;
|
|
|
|
var r = new Models.Recruits.Recruit();
|
|
r.ExamId = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.ExamID)]?.GetValue<string>();
|
|
r.CitizenId = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.PersonalID)]?.GetValue<string>();
|
|
r.Prefix = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Prefix)]?.GetValue<string>();
|
|
r.FirstName = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.FirstName)]?.GetValue<string>();
|
|
r.LastName = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.LastName)]?.GetValue<string>();
|
|
r.Gendor = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Gender)]?.GetValue<string>();
|
|
r.National = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.National)]?.GetValue<string>().IsNull("");
|
|
r.Race = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Race)]?.GetValue<string>().IsNull("");
|
|
r.Religion = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Religion)]?.GetValue<string>().IsNull("");
|
|
r.DateOfBirth = Convert.ToDateTime(workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.DateOfBirth)]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-"));
|
|
r.Marry = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Marry)]?.GetValue<string>();
|
|
r.Isspecial = "N";
|
|
r.CitizenCardIssuer = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.PersonalCardIssue)]?.GetValue<string>();
|
|
r.CitizenCardExpireDate = Convert.ToDateTime(workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.PersonalCardExpireDate)]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-"));
|
|
r.ApplyDate = (DateTime)workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.ApplyDate)]?.GetValue<DateTime>();
|
|
r.PositionName = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.PositionName)]?.GetValue<string>().IsNull("");
|
|
r.PositionType = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.PositionType)]?.GetValue<string>().IsNull("");
|
|
r.PositionLevel = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.PositionLevel)]?.GetValue<string>().IsNull("");
|
|
|
|
|
|
// address
|
|
r.Addresses.Add(new RecruitAddress()
|
|
{
|
|
Address = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Address)]?.GetValue<string>() ?? "",
|
|
Moo = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Moo)]?.GetValue<string>() ?? "",
|
|
Soi = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Soi)]?.GetValue<string>() ?? "",
|
|
Road = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Road)]?.GetValue<string>() ?? "",
|
|
District = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.District)]?.GetValue<string>() ?? "",
|
|
Amphur = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Amphur)]?.GetValue<string>() ?? "",
|
|
Province = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Province)]?.GetValue<string>() ?? "",
|
|
ZipCode = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.ZipCode)]?.GetValue<string>() ?? "",
|
|
Telephone = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Telephone)]?.GetValue<string>() ?? "",
|
|
Mobile = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Mobile)]?.GetValue<string>() ?? "",
|
|
Address1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Address1)]?.GetValue<string>() ?? "",
|
|
Moo1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Moo1)]?.GetValue<string>() ?? "",
|
|
Soi1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Soi1)]?.GetValue<string>() ?? "",
|
|
Road1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Road1)]?.GetValue<string>() ?? "",
|
|
District1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.District1)]?.GetValue<string>() ?? "",
|
|
Amphur1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Amphur1)]?.GetValue<string>() ?? "",
|
|
Province1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Province1)]?.GetValue<string>() ?? "",
|
|
ZipCode1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.ZipCode1)]?.GetValue<string>() ?? "",
|
|
});
|
|
|
|
// payment
|
|
r.Payments.Add(new RecruitPayment()
|
|
{
|
|
PaymentId = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.PaymentID)]?.GetValue<string>() ?? "",
|
|
CompanyCode = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.CompanyCode)]?.GetValue<string>() ?? "",
|
|
TextFile = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.TextFile)]?.GetValue<string>() ?? "",
|
|
BankCode = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.BankCode)]?.GetValue<string>() ?? "",
|
|
AccountNumber = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.AccouontNumer)]?.GetValue<string>() ?? "",
|
|
TransDate = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.TransDate)]?.GetValue<string>() ?? "",
|
|
TransTime = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.TransTime)]?.GetValue<string>() ?? "",
|
|
CustomerName = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.CustomerName)]?.GetValue<string>() ?? "",
|
|
RefNo1 = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.RefNo1)]?.GetValue<string>() ?? "",
|
|
TermBranch = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.TermBranch)]?.GetValue<string>() ?? "",
|
|
TellerId = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.TellerID)]?.GetValue<string>() ?? "",
|
|
CreditDebit = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.CreditDebit)]?.GetValue<string>() ?? "",
|
|
PaymentType = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Type)]?.GetValue<string>(),
|
|
ChequeNo = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.ChequeNo)]?.GetValue<string>() ?? "",
|
|
Amount = (decimal)workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Amount)]?.GetValue<decimal>(),
|
|
ChqueBankCode = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.ChqBankCode)]?.GetValue<string>() ?? ""
|
|
});
|
|
|
|
// occupation
|
|
r.Occupations.Add(new RecruitOccupation()
|
|
{
|
|
Occupation = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Occupation)]?.GetValue<string>() ?? "",
|
|
Position = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Position)]?.GetValue<string>() ?? "",
|
|
Workplace = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Workplace)]?.GetValue<string>() ?? "",
|
|
Telephone = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.WorkplaceTelephone)]?.GetValue<string>() ?? "",
|
|
WorkAge = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.WorkAge)]?.GetValue<string>() ?? "",
|
|
});
|
|
|
|
// certificate
|
|
r.Certificates.Add(new RecruitCertificate()
|
|
{
|
|
CertificateNo = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.CertificateNo)]?.GetValue<string>() ?? "",
|
|
Description = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.CertificateDesc)]?.GetValue<string>() ?? "",
|
|
IssueDate = Convert.ToDateTime(workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.CertificateIssueDate)]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")),
|
|
ExpiredDate = Convert.ToDateTime(workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.CertificateExpireDate)]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-"))
|
|
});
|
|
|
|
r.Educations.Add(new RecruitEducation()
|
|
{
|
|
Degree = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Degree)]?.GetValue<string>() ?? "",
|
|
Major = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.Major)]?.GetValue<string>() ?? "",
|
|
MajorGroupId = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.MajorGroupID)]?.GetValue<string>() ?? "",
|
|
MajorGroupName = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.MajorGroupName)]?.GetValue<string>() ?? "",
|
|
University = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.University)]?.GetValue<string>() ?? "",
|
|
GPA = (double)workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.GPA)]?.GetValue<double>(),
|
|
Specialist = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.SpecialList)]?.GetValue<string>() ?? "",
|
|
HighDegree = workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.HighDegree)]?.GetValue<string>() ?? "",
|
|
BachelorDate = Convert.ToDateTime(workSheet?.Cells[row, GetColumnIndex(cols, CandidateFileHeader.BachelorDate)]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-"))
|
|
});
|
|
|
|
r.RecruitImport = imported;
|
|
_context.Recruits.Add(r);
|
|
|
|
//imported.Recruits.Add(r);
|
|
row++;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
// finally save to database
|
|
|
|
_context.SaveChanges();
|
|
|
|
return Success();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await _minioService.DeleteFileAsync(Guid.Parse(import_doc_id));
|
|
return Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
if (System.IO.File.Exists(importFile))
|
|
System.IO.File.Delete(importFile);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ลบข้อมูลนำข้อมูลผู้สมัครสอบแข่งขัน
|
|
/// </summary>
|
|
/// <param name="id">รหัสรอบการสอบแข่งขัน</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำนำเข้าข้อมูลสำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpDelete("candidate/{id:length(36)}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> DeleteCandidateFileAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("DELETE", "SYS_EXAM_CONTEST");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var data = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.ImportHostories)
|
|
.Include(x => x.ImportFile)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Addresses)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Occupations)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Certificates)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Educations)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Payments)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Documents)
|
|
.ThenInclude(x => x.DocumentFile)
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.ImportFile)
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.Scores)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (data == null)
|
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
|
|
|
var rec_import_id = data.ImportFile.Id.ToString("D");
|
|
var score_import_id = data.ScoreImport != null ? data.ScoreImport.ImportFile.Id.ToString("D") : "-";
|
|
|
|
_context.RecruitImports.Remove(data);
|
|
await _context.SaveChangesAsync();
|
|
|
|
// delete upload candidate file
|
|
await _minioService.DeleteFileAsync(Guid.Parse(rec_import_id));
|
|
|
|
// delete score file
|
|
if (score_import_id != "-")
|
|
await _minioService.DeleteFileAsync(Guid.Parse(score_import_id));
|
|
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// แสดงประวัติการนำเข้าข้อมูลการสอบแข่งขัน
|
|
/// </summary>
|
|
/// <param name="id">รหัสรอบการสอบแข่งขัน</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำนำเข้าข้อมูลสำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("history/{id:length(36)}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetImportHistoryAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_EXAM_CONTEST");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var data = await _context.RecruitImportHistories.AsQueryable()
|
|
.Include(x => x.RecruitImport)
|
|
.Where(x => x.RecruitImport.Id == id)
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
.ToListAsync();
|
|
|
|
return Success(data);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// นำเข้ารายชื่อผู้สมัครสอบแข่งขัน (ข้อมูลผู้สมัครสอบ)
|
|
/// </summary>
|
|
/// <param name="id">รหัสรอบการสอบแข่งขัน</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำนำเข้าข้อมูลสำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("candidate/{id:length(36)}"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> ImportCandidateFileByIdAsync(Guid id)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_EXAM_CONTEST");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var tmpDir = Path.Combine(_webHostEnvironment.ContentRootPath, "tmp");
|
|
if (!Directory.Exists(tmpDir))
|
|
Directory.CreateDirectory(tmpDir);
|
|
|
|
var importFile = Path.Combine(tmpDir, $"c_{DateTime.Now.ToString("ddMMyyyyHHmmss")}.xlsx");
|
|
var import_doc_id = "";
|
|
|
|
try
|
|
{
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
|
|
var imported = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.ImportHostories)
|
|
.Include(x => x.ImportFile)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Addresses)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Occupations)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Certificates)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Educations)
|
|
.Include(x => x.Recruits)
|
|
.ThenInclude(x => x.Payments)
|
|
.Include(x => x.Recruits)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (imported == null)
|
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
|
|
|
if (imported.Recruits != null)
|
|
{
|
|
// remove old score data
|
|
_context.Recruits.RemoveRange(imported.Recruits);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
var file = Request.Form.Files[0];
|
|
var doc = await _minioService.UploadFileAsync(file);
|
|
import_doc_id = doc.Id.ToString("D");
|
|
|
|
var fileContent = (await _minioService.DownloadFileAsync(doc.Id)).FileContent;
|
|
|
|
// สร้างรอบการบรรจุ โดยเอาเข้ามูลมาใส่จาก Request
|
|
imported.ImportHostories.Add(new RecruitImportHistory
|
|
{
|
|
Description = "นำเข้าข้อมูลผู้สมัครสอบแข่งขัน",
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
});
|
|
|
|
//await _context.RecruitImports.AddAsync(imported);
|
|
|
|
// import datafile
|
|
System.IO.File.WriteAllBytes(importFile, fileContent);
|
|
|
|
using (var c_package = new ExcelPackage(new FileInfo(importFile)))
|
|
{
|
|
// loop from sheet2 to end
|
|
|
|
for (int i = 0; i < c_package.Workbook.Worksheets.Count; i++)
|
|
{
|
|
var workSheet = c_package.Workbook.Worksheets[i];
|
|
var totalRows = workSheet.Dimension.Rows;
|
|
var cols = workSheet.GetHeaderColumns();
|
|
|
|
int row = 2;
|
|
|
|
while (row <= totalRows)
|
|
{
|
|
var cell1 = workSheet?.Cells[row, 1]?.GetValue<string>();
|
|
if (cell1 == "" || cell1 == null) break;
|
|
|
|
var r = new Models.Recruits.Recruit();
|
|
r.ExamId = workSheet?.Cells[row, 1]?.GetValue<string>() ?? "";
|
|
r.PositionName = workSheet?.Cells[row, 3]?.GetValue<string>() ?? "";
|
|
r.HddPosition = workSheet?.Cells[row, 4]?.GetValue<string>() ?? "";
|
|
r.Prefix = workSheet?.Cells[row, 5]?.GetValue<string>() == "อื่น ๆ" ? workSheet?.Cells[row, 6]?.GetValue<string>() ?? "" : workSheet?.Cells[row, 5]?.GetValue<string>() ?? "";
|
|
r.FirstName = workSheet?.Cells[row, 7]?.GetValue<string>() ?? "";
|
|
r.LastName = workSheet?.Cells[row, 8]?.GetValue<string>() ?? "";
|
|
r.Gendor = workSheet?.Cells[row, 98]?.GetValue<string>() ?? "";
|
|
r.National = workSheet?.Cells[row, 9]?.GetValue<string>() ?? "";
|
|
r.Race = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
|
|
r.Religion = workSheet?.Cells[row, 10]?.GetValue<string>() ?? "";
|
|
r.DateOfBirth = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 11]?.GetValue<string>()) ? _recruitService.CheckDateTime(workSheet?.Cells[row, 11]?.GetValue<string>() ?? "", "dd/MM/yyyy") : DateTime.MinValue;
|
|
r.CitizenId = workSheet?.Cells[row, 12]?.GetValue<string>() ?? "";
|
|
r.typeTest = workSheet?.Cells[row, 13]?.GetValue<string>() ?? "";
|
|
r.Marry = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
|
|
r.Isspecial = "N";
|
|
r.CitizenCardIssuer = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
|
|
r.CitizenCardExpireDate = Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-"));
|
|
r.ApplyDate = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 87]?.GetValue<string>()) ? _recruitService.CheckDateTime(workSheet?.Cells[row, 87]?.GetValue<string>() ?? "", "dd/MM/yyyy") : DateTime.MinValue;
|
|
r.PositionType = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
|
|
r.PositionLevel = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
|
|
|
|
r.CreatedAt = DateTime.Now;
|
|
r.CreatedUserId = UserId ?? "";
|
|
r.CreatedFullName = FullName ?? "System Administrator";
|
|
r.LastUpdatedAt = DateTime.Now;
|
|
r.LastUpdateUserId = UserId ?? "";
|
|
r.LastUpdateFullName = FullName ?? "System Administrator";
|
|
|
|
// education
|
|
r.Educations.Add(new RecruitEducation()
|
|
{
|
|
Degree = workSheet?.Cells[row, 18]?.GetValue<string>() ?? "",
|
|
Major = workSheet?.Cells[row, 19]?.GetValue<string>() == "อื่น ๆ" ? workSheet?.Cells[row, 20]?.GetValue<string>() ?? "" : workSheet?.Cells[row, 19]?.GetValue<string>() ?? "",
|
|
MajorGroupId = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
|
|
MajorGroupName = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
|
|
University = workSheet?.Cells[row, 21]?.GetValue<string>() == "อื่น ๆ" ? workSheet?.Cells[row, 22]?.GetValue<string>() ?? "" : workSheet?.Cells[row, 21]?.GetValue<string>() ?? "",
|
|
GPA = (double)workSheet?.Cells[row, 26]?.GetValue<double>(),
|
|
Specialist = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
|
|
HighDegree = workSheet?.Cells[row, 27]?.GetValue<string>() ?? "",
|
|
BachelorDate = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 25]?.GetValue<string>()) ? _recruitService.CheckDateTime(workSheet?.Cells[row, 11]?.GetValue<string>() ?? "", "dd/MM/yyyy") : DateTime.MinValue,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdateFullName = FullName ?? "System Administrator"
|
|
});
|
|
|
|
// occupation
|
|
r.Occupations.Add(new RecruitOccupation()
|
|
{
|
|
Occupation = workSheet?.Cells[row, 33]?.GetValue<string>() == "อื่น ๆ" ? workSheet?.Cells[row, 34]?.GetValue<string>() ?? "" : workSheet?.Cells[row, 33]?.GetValue<string>() ?? "",
|
|
Position = workSheet?.Cells[row, 37]?.GetValue<string>() ?? "",
|
|
Workplace = $"{(workSheet?.Cells[row, 36]?.GetValue<string>() ?? "")} {(workSheet?.Cells[row, 35]?.GetValue<string>() ?? "")}",
|
|
Telephone = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
|
|
WorkAge = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdateFullName = FullName ?? "System Administrator"
|
|
});
|
|
|
|
// address
|
|
r.Addresses.Add(new RecruitAddress()
|
|
{
|
|
Address = $"{(workSheet?.Cells[row, 49]?.GetValue<string>() ?? "")} {(workSheet?.Cells[row, 50]?.GetValue<string>() ?? "")}",
|
|
Moo = workSheet?.Cells[row, 51]?.GetValue<string>() ?? "",
|
|
Soi = workSheet?.Cells[row, 52]?.GetValue<string>() ?? "",
|
|
Road = workSheet?.Cells[row, 53]?.GetValue<string>() ?? "",
|
|
District = workSheet?.Cells[row, 54]?.GetValue<string>() ?? "",
|
|
Amphur = workSheet?.Cells[row, 55]?.GetValue<string>() ?? "",
|
|
Province = workSheet?.Cells[row, 56]?.GetValue<string>() ?? "",
|
|
ZipCode = workSheet?.Cells[row, 57]?.GetValue<string>() ?? "",
|
|
Telephone = workSheet?.Cells[row, 58]?.GetValue<string>() ?? "",
|
|
Mobile = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
|
|
Address1 = $"{(workSheet?.Cells[row, 61]?.GetValue<string>() ?? "")} {(workSheet?.Cells[row, 62]?.GetValue<string>() ?? "")}",
|
|
Moo1 = workSheet?.Cells[row, 63]?.GetValue<string>() ?? "",
|
|
Soi1 = workSheet?.Cells[row, 64]?.GetValue<string>() ?? "",
|
|
Road1 = workSheet?.Cells[row, 65]?.GetValue<string>() ?? "",
|
|
District1 = workSheet?.Cells[row, 66]?.GetValue<string>() ?? "",
|
|
Amphur1 = workSheet?.Cells[row, 67]?.GetValue<string>() ?? "",
|
|
Province1 = workSheet?.Cells[row, 68]?.GetValue<string>() ?? "",
|
|
ZipCode1 = workSheet?.Cells[row, 69]?.GetValue<string>() ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdateFullName = FullName ?? "System Administrator"
|
|
});
|
|
|
|
// payment
|
|
r.Payments.Add(new RecruitPayment()
|
|
{
|
|
PaymentId = workSheet?.Cells[row, 104]?.GetValue<string>() ?? "",
|
|
CompanyCode = workSheet?.Cells[row, 105]?.GetValue<string>() ?? "",
|
|
TextFile = workSheet?.Cells[row, 106]?.GetValue<string>() ?? "",
|
|
BankCode = workSheet?.Cells[row, 107]?.GetValue<string>() ?? "",
|
|
AccountNumber = workSheet?.Cells[row, 108]?.GetValue<string>() ?? "",
|
|
TransDate = workSheet?.Cells[row, 109]?.GetValue<string>() ?? "",
|
|
TransTime = workSheet?.Cells[row, 110]?.GetValue<string>() ?? "",
|
|
CustomerName = workSheet?.Cells[row, 111]?.GetValue<string>() ?? "",
|
|
RefNo1 = workSheet?.Cells[row, 112]?.GetValue<string>() ?? "",
|
|
TermBranch = workSheet?.Cells[row, 113]?.GetValue<string>() ?? "",
|
|
TellerId = workSheet?.Cells[row, 114]?.GetValue<string>() ?? "",
|
|
CreditDebit = workSheet?.Cells[row, 115]?.GetValue<string>() ?? "",
|
|
PaymentType = workSheet?.Cells[row, 116]?.GetValue<string>(),
|
|
ChequeNo = workSheet?.Cells[row, 117]?.GetValue<string>() ?? "",
|
|
Amount = (decimal)workSheet?.Cells[row, 118]?.GetValue<decimal>(),
|
|
ChqueBankCode = workSheet?.Cells[row, 119]?.GetValue<string>() ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdateFullName = FullName ?? "System Administrator"
|
|
});
|
|
|
|
// certificate
|
|
r.Certificates.Add(new RecruitCertificate()
|
|
{
|
|
CertificateNo = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
|
|
Description = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
|
|
IssueDate = Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")),
|
|
ExpiredDate = Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")),
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdateFullName = FullName ?? "System Administrator"
|
|
});
|
|
|
|
r.RecruitImport = imported;
|
|
_context.Recruits.Add(r);
|
|
|
|
//imported.Recruits.Add(r);
|
|
row++;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
// finally save to database
|
|
|
|
_context.SaveChanges();
|
|
|
|
return Success();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await _minioService.DeleteFileAsync(Guid.Parse(import_doc_id));
|
|
return Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
if (System.IO.File.Exists(importFile))
|
|
System.IO.File.Delete(importFile);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Score File "
|
|
/// <summary>
|
|
/// นำเข้าผลคะแนนสอบแข่งขัน (บัญชีรวมคะแนน)
|
|
/// </summary>
|
|
/// <param name="id">รหัสรอบการสอบแข่งขัน</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำนำเข้าข้อมูลสำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("score/{id:length(36)}"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> ImportScoreFileAsync(Guid id)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_EXAM_CONTEST");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var tmpDir = Path.Combine(_webHostEnvironment.ContentRootPath, "tmp");
|
|
if (!Directory.Exists(tmpDir))
|
|
Directory.CreateDirectory(tmpDir);
|
|
|
|
var importFile = Path.Combine(tmpDir, $"s_{DateTime.Now.ToString("ddMMyyyyHHmmss")}.xlsx");
|
|
var import_doc_id = "";
|
|
|
|
try
|
|
{
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
|
|
var rec_import = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.Scores)
|
|
.Include(x => x.ImportHostories)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (rec_import == null)
|
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
|
|
|
if (rec_import.ScoreImport != null)
|
|
{
|
|
// remove old score data
|
|
if (rec_import.ScoreImport.Scores != null)
|
|
{
|
|
_context.RecruitScores.RemoveRange(rec_import.ScoreImport.Scores);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|
|
|
|
var file = Request.Form.Files[0];
|
|
var doc = await _minioService.UploadFileAsync(file);
|
|
import_doc_id = doc.Id.ToString("D");
|
|
|
|
Console.WriteLine($"file id = {import_doc_id}");
|
|
|
|
var fileContent = (await _minioService.DownloadFileAsync(doc.Id)).FileContent;
|
|
|
|
// create import history
|
|
rec_import.ImportHostories.Add(new RecruitImportHistory
|
|
{
|
|
Description = "นำเข้าข้อมูลผลคะแนนสอบ",
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
});
|
|
|
|
// create new file import
|
|
var imported = new ScoreImport
|
|
{
|
|
Year = rec_import.Year,
|
|
ImportFile = doc,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
Scores = new List<RecruitScore>()
|
|
};
|
|
|
|
// preload recruits ทั้งหมดของครั้งเดียว และ Group ExamId เอาเฉพาะ key ที่ไม่ซ้ำ
|
|
var recruitsDict = await _context.Recruits
|
|
.Where(x => x.RecruitImport.Id == rec_import.Id)
|
|
.GroupBy(x => x.ExamId)
|
|
.Where(g => g.Count() == 1)
|
|
.Select(g => g.First())
|
|
.ToDictionaryAsync(x => x.ExamId, x => x);
|
|
|
|
// import datafile
|
|
System.IO.File.WriteAllBytes(importFile, fileContent);
|
|
|
|
using (var c_package = new ExcelPackage(new FileInfo(importFile)))
|
|
{
|
|
for (int i = 0; i < c_package.Workbook.Worksheets.Count; i++)
|
|
{
|
|
var workSheet = c_package.Workbook.Worksheets[i];
|
|
var totalRows = workSheet.Dimension.Rows;
|
|
var cols = workSheet.GetHeaderColumns();
|
|
|
|
int row = 8;
|
|
|
|
while (row <= totalRows)
|
|
{
|
|
var cell1 = workSheet?.Cells[row, 1]?.GetValue<string>();
|
|
if (cell1 == "" || cell1 == null) break;
|
|
|
|
var r = new RecruitScore();
|
|
|
|
#region นำเข้าผลคะแนนสอบแข่งขัน old
|
|
|
|
//r.ExamId = workSheet?.Cells[row, 2]?.GetValue<string>();
|
|
|
|
//r.FullA = (int)workSheet?.Cells[7, 7]?.GetValue<string>().Replace("(", "").Replace(")", "").Replace("คะแนน", "").Trim().ToInteger();
|
|
//r.SumA = workSheet?.Cells[row, 7]?.GetValue<string>() == "ขส." ? 0.00 : (double)workSheet?.Cells[row, 7]?.GetValue<double>();
|
|
//r.PercentageA = workSheet?.Cells[row, 8]?.GetValue<string>() == "ขส." ? 0.0 : (double)workSheet?.Cells[row, 8]?.GetValue<double>();
|
|
//r.AStatus = workSheet?.Cells[row, 9]?.GetValue<string>();
|
|
|
|
//r.FullB = (int)workSheet?.Cells[7, 12]?.GetValue<string>().Replace("(", "").Replace(")", "").Replace("คะแนน", "").Trim().ToInteger();
|
|
//r.SumB = workSheet?.Cells[row, 12]?.GetValue<string>() == "ขส." ? 0.00 : (double)workSheet?.Cells[row, 12]?.GetValue<double>();
|
|
//r.PercentageB = workSheet?.Cells[row, 13]?.GetValue<string>() == "ขส." ? 0.0 : (double)workSheet?.Cells[row, 13]?.GetValue<double>();
|
|
//r.BStatus = workSheet?.Cells[row, 14]?.GetValue<string>();
|
|
|
|
//r.SumAB = workSheet?.Cells[row, 15]?.GetValue<string>() == "ขส." ? 0.00 : (double)workSheet?.Cells[row, 15]?.GetValue<double>();
|
|
//r.ABStatus = workSheet?.Cells[row, 17]?.GetValue<string>();
|
|
|
|
//r.FullC = (int)workSheet?.Cells[7, 20]?.GetValue<string>().Replace("(", "").Replace(")", "").Replace("คะแนน", "").Trim().ToInteger();
|
|
//r.SumC = workSheet?.Cells[row, 20]?.GetValue<string>() == "ขส." ? 0.00 : (double)workSheet?.Cells[row, 20]?.GetValue<double>();
|
|
//r.PercentageC = workSheet?.Cells[row, 21]?.GetValue<string>() == "ขส." ? 0.0 : (double)workSheet?.Cells[row, 21]?.GetValue<double>();
|
|
//r.CStatus = workSheet?.Cells[row, 22]?.GetValue<string>();
|
|
|
|
//r.ExamStatus = workSheet?.Cells[row, 24]?.GetValue<string>();
|
|
//r.Number = workSheet?.Cells[row, 25]?.GetValue<string>() ?? ""; // ตัดนำเข้า ลำดับที่สอบได้ เพราะจะแยกเป็นอีกส่วน #1787
|
|
|
|
//r.Major = workSheet.Name;
|
|
|
|
#endregion
|
|
|
|
r.ExamId = workSheet?.Cells[row, 2]?.GetValue<string>();
|
|
|
|
//var recruit = await _context.Recruits.AsQueryable()
|
|
// .Include(x => x.RecruitImport)
|
|
// .Where(x => x.RecruitImport == rec_import && x.ExamId == r.ExamId)
|
|
// .FirstOrDefaultAsync();
|
|
|
|
// ใช้ dictionary lookup แทน query DB ทีละรอบ
|
|
if (!string.IsNullOrEmpty(r.ExamId) && recruitsDict.TryGetValue(r.ExamId, out var recruit))
|
|
{
|
|
var apiUrl = $"{_configuration["API"]}/org/find/head/officer";
|
|
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();
|
|
if (_res.IsSuccessStatusCode)
|
|
{
|
|
var org = JsonConvert.DeserializeObject<dynamic>(_result);
|
|
recruit.AuthName = org.result.name == null ? "" : org.result.name;
|
|
recruit.AuthPosition = org.result.position == null ? "" : org.result.position;
|
|
}
|
|
}
|
|
|
|
r.CitizenId = workSheet?.Cells[row, 3]?.GetValue<string>();
|
|
|
|
// ภาคความรู้ความสามารถที่ใช้เฉพาะตำแหน่ง
|
|
r.FullA = 200;
|
|
r.SumA = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 5]?.GetValue<string>()) ? 0.00 : Math.Round(workSheet.Cells[row, 5].GetValue<double>(), 2);
|
|
r.PercentageA = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 6]?.GetValue<string>()) ? 0.00 : Math.Round(workSheet.Cells[row, 6].GetValue<double>(), 2);
|
|
r.AStatus = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 7]?.GetValue<string>()) ? "" : workSheet?.Cells[row, 7]?.GetValue<string>();
|
|
r.SumAB = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 5]?.GetValue<string>()) ? 0.00 : Math.Round(workSheet.Cells[row, 5].GetValue<double>(), 2);
|
|
r.ABStatus = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 7]?.GetValue<string>()) ? "" : workSheet?.Cells[row, 7]?.GetValue<string>();
|
|
|
|
// ภาคความเหมาะสมกับตำแหน่ง
|
|
r.FullC = 50;
|
|
r.SumC = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 8]?.GetValue<string>()) ? 0.00 : Math.Round(workSheet.Cells[row, 8].GetValue<double>(), 2);
|
|
r.FullD = 50;
|
|
r.SumD = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 9]?.GetValue<string>()) ? 0.00 : Math.Round(workSheet.Cells[row, 9].GetValue<double>(), 2);
|
|
r.SumCD = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 10]?.GetValue<string>()) ? 0.00 : Math.Round(workSheet.Cells[row, 10].GetValue<double>(), 2);
|
|
r.PercentageC = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 11]?.GetValue<string>()) ? 0.00 : Math.Round(workSheet.Cells[row, 11].GetValue<double>(), 2);
|
|
r.CStatus = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 12]?.GetValue<string>()) ? "" : workSheet?.Cells[row, 12]?.GetValue<string>();
|
|
r.FullScore = 300;
|
|
r.TotalScore = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 13]?.GetValue<string>()) ? 0.00 : Math.Round(workSheet.Cells[row, 13].GetValue<double>(), 2);
|
|
|
|
if (workSheet?.Cells[row, 7]?.GetValue<string>() == "ขาดสอบ")
|
|
{
|
|
r.ExamStatus = "ขส.";
|
|
}
|
|
else if (workSheet?.Cells[row, 14]?.GetValue<string>() == "ได้")
|
|
{
|
|
r.ExamStatus = "ผ่าน";
|
|
}
|
|
else if (workSheet?.Cells[row, 14]?.GetValue<string>() == "ตก")
|
|
{
|
|
r.ExamStatus = "ไม่ผ่าน";
|
|
}
|
|
else
|
|
{
|
|
r.ExamStatus = "-";
|
|
}
|
|
|
|
r.RemarkScore = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 15]?.GetValue<string>()) ? string.Empty : workSheet?.Cells[row, 15]?.GetValue<string>();
|
|
r.Major = workSheet.Name;
|
|
|
|
r.CreatedAt = DateTime.Now;
|
|
r.CreatedUserId = UserId ?? "";
|
|
r.CreatedFullName = FullName ?? "System Administrator";
|
|
r.LastUpdatedAt = DateTime.Now;
|
|
r.LastUpdateUserId = UserId ?? "";
|
|
r.LastUpdateFullName = FullName ?? "System Administrator";
|
|
|
|
imported.Scores.Add(r);
|
|
}
|
|
|
|
row++;
|
|
|
|
} // end of sheet loop
|
|
} // end of all file loop
|
|
}
|
|
|
|
// finally save to database
|
|
rec_import.ScoreImport = imported;
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//await _minioService.DeleteFileAsync(Guid.Parse(import_doc_id));
|
|
return Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
if (System.IO.File.Exists(importFile))
|
|
System.IO.File.Delete(importFile);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Result File "
|
|
/// <summary>
|
|
/// นำเข้าผลการสอบแข่งขัน (ผลการสอบ)
|
|
/// </summary>
|
|
/// <param name="id">รหัสรอบการสอบแข่งขัน</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำนำเข้าข้อมูลสำเร็จ</response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("result/{id:length(36)}"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> ImportResultFileAsync(Guid id)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_EXAM_CONTEST");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
|
|
try
|
|
{
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
|
|
var rec_import = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.Scores)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (rec_import == null)
|
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
|
|
|
// update ฟิลด์ลำดับที่สอบได้และหมายเหตุจากลำดับที่สอบได้อันเก่าก่อน
|
|
if (rec_import.ScoreImport != null && rec_import.ScoreImport.Scores != null)
|
|
{
|
|
var _oldScores = rec_import.ScoreImport.Scores
|
|
.Where(x => !string.IsNullOrEmpty(x.Number))
|
|
.ToList();
|
|
if (_oldScores.Count > 0)
|
|
{
|
|
foreach (var x in _oldScores)
|
|
{
|
|
x.Number = string.Empty;
|
|
x.RemarkExamOrder = string.Empty;
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|
|
|
|
// create import history
|
|
rec_import.ImportHostories.Add(new RecruitImportHistory
|
|
{
|
|
Description = "นำเข้าข้อมูลผลการสอบ",
|
|
CreatedAt = DateTime.Now,
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
});
|
|
|
|
// preload score
|
|
var score = rec_import.ScoreImport.Scores
|
|
.Where(s => !string.IsNullOrEmpty(s.ExamId))
|
|
.ToDictionary(s => s.ExamId, s => s);
|
|
|
|
// ถ้าไม่มีผลคะแนนสอบแข่งขันให้จบการทำงาน
|
|
if (score.Count == 0) return Success();
|
|
|
|
var file = Request.Form.Files[0];
|
|
using (var stream = file.OpenReadStream())
|
|
using (var c_package = new ExcelPackage(stream))
|
|
{
|
|
foreach (var workSheet in c_package.Workbook.Worksheets)
|
|
{
|
|
var totalRows = workSheet.Dimension.Rows;
|
|
int row = 7; // เริ่มที่ row 7 ตามตัวอย่างไฟล์
|
|
|
|
while (row <= totalRows)
|
|
{
|
|
var examId = workSheet?.Cells[row, 2]?.GetValue<string>();
|
|
if (string.IsNullOrWhiteSpace(examId))
|
|
{
|
|
row++;
|
|
continue;
|
|
}
|
|
|
|
if (score.TryGetValue(examId, out var existingScore))
|
|
{
|
|
existingScore.Number = workSheet?.Cells[row, 1]?.GetValue<string>();
|
|
existingScore.RemarkExamOrder = workSheet?.Cells[row, 4]?.GetValue<string>() ?? string.Empty;
|
|
existingScore.LastUpdatedAt = DateTime.Now;
|
|
existingScore.LastUpdateUserId = UserId ?? "";
|
|
existingScore.LastUpdateFullName = FullName ?? "System Administrator";
|
|
}
|
|
|
|
row++;
|
|
}
|
|
}
|
|
}
|
|
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Exam Information "
|
|
|
|
/// <summary>
|
|
/// แสดงข้อมูลสำหรับหน้าจอ : รายการข้อมูลผู้สมัครสอบ
|
|
/// </summary>
|
|
[HttpGet("exam")]
|
|
public async Task<ActionResult<ResponseObject>> GetExamResultAsync()
|
|
{
|
|
try
|
|
{
|
|
var data = await _context.RecruitImports.AsQueryable()
|
|
.OrderByDescending(x => x.Year)
|
|
.ThenByDescending(x => x.Order)
|
|
.Select(x => new
|
|
{
|
|
x.Id,
|
|
ExamYear = x.Year.ToThaiYear(),
|
|
ExamOrder = x.Order,
|
|
Description = x.Name,
|
|
})
|
|
.ToListAsync();
|
|
|
|
var result = new List<dynamic>();
|
|
|
|
foreach (var d in data)
|
|
{
|
|
result.Add(new
|
|
{
|
|
ExamYear = d.ExamYear,
|
|
Decription = d.Description,
|
|
ExamCount = await GetExamCount(d.Id),
|
|
PassCount = await GetPassExamCount(d.Id),
|
|
NotPassCount = (await GetExamCount(d.Id) - await GetPassExamCount(d.Id))
|
|
});
|
|
}
|
|
|
|
return Success(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
[HttpPost("exam/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> GetExamResultById([FromBody] RecruitExamRequest req, Guid id)
|
|
{
|
|
try
|
|
{
|
|
var p_Id = new MySqlParameter("@id", id);
|
|
var data = new List<dynamic>();
|
|
using (var cmd = _context.Database.GetDbConnection().CreateCommand())
|
|
{
|
|
cmd.CommandTimeout = 0;
|
|
var sb = new StringBuilder();
|
|
cmd.Parameters.Clear();
|
|
sb.Clear();
|
|
sb.Append(" SELECT * ");
|
|
sb.Append(" FROM exam_info ");
|
|
sb.Append(" WHERE recruit_import_id = @id ");
|
|
cmd.Parameters.Add(p_Id);
|
|
|
|
if (req.ExamAttribute != null && req.ExamAttribute != "")
|
|
{
|
|
sb.Append(" AND examAttribute = @a ");
|
|
cmd.Parameters.Add(new MySqlParameter("@a", req.ExamAttribute));
|
|
}
|
|
|
|
if (req.ExamResult != null && req.ExamResult != "")
|
|
{
|
|
sb.Append(" AND result = @r ");
|
|
cmd.Parameters.Add(new MySqlParameter("@r", req.ExamResult));
|
|
}
|
|
|
|
cmd.CommandText = sb.ToString();
|
|
|
|
_context.Database.OpenConnection();
|
|
var da = new MySqlDataAdapter(cmd as MySqlCommand);
|
|
var dt = new DataTable();
|
|
da.Fill(dt);
|
|
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
data.Add(new
|
|
{
|
|
examID = dr["examID"].ToString(),
|
|
profileID = dr["profileID"].ToString(),
|
|
prefix = dr["prefix"].ToString(),
|
|
fullName = dr["fullName"].ToString(),
|
|
dateOfBirth = dr["dateofbirth"] == null || Convert.ToDateTime(dr["dateofbirth"]) == DateTime.MinValue ? "" : Convert.ToDateTime(dr["dateofbirth"]).ToThaiShortDate(),
|
|
gender = dr["gender"].ToString(),
|
|
degree = dr["degree"].ToString(),
|
|
major = dr["major"].ToString(),
|
|
majorgroup = dr["majorgroup"].ToString(),
|
|
certificateNo = dr["certificateno"].ToString(),
|
|
certificateIssueDate = dr["certificateIssueDate"] == null || Convert.ToDateTime(dr["certificateIssueDate"]) == DateTime.MinValue ? "" : Convert.ToDateTime(dr["certificateIssueDate"]).ToThaiShortDate(),
|
|
ExamScore = string.IsNullOrWhiteSpace(dr["score"]?.ToString()) ? 0 : decimal.Parse(dr["score"]?.ToString()),
|
|
ExamResult = dr["result"].ToString(),
|
|
ExamAttribute = dr["examAttribute"].ToString(),
|
|
Remark = dr["remark"].ToString(),
|
|
IsSpecial = dr["isspecial"].ToString(),
|
|
applyDate = dr["applydate"] == null || Convert.ToDateTime(dr["applydate"]) == DateTime.MinValue ? "" : Convert.ToDateTime(dr["applydate"]).ToThaiShortDate(),
|
|
university = dr["university"].ToString(),
|
|
position_name = dr["position_name"].ToString(),
|
|
hddPosition = dr["hddPosition"].ToString(),
|
|
typeTest = dr["typeTest"].ToString(),
|
|
position_level = dr["position_level"].ToString(),
|
|
position_type = dr["position_type"].ToString(),
|
|
exam_name = dr["exam_name"].ToString(),
|
|
exam_order = dr["exam_order"].ToString(),
|
|
score_year = Convert.ToInt32(dr["score_year"]).ToThaiYear().ToString(),
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
dynamic header = null;
|
|
using (var cmd = _context.Database.GetDbConnection().CreateCommand())
|
|
{
|
|
var sb = new StringBuilder();
|
|
cmd.CommandTimeout = 0;
|
|
cmd.Parameters.Clear();
|
|
sb.Clear();
|
|
sb.Append(" SELECT * ");
|
|
sb.Append(" FROM sum_exam_info ");
|
|
sb.Append(" WHERE recruit_import_id = @id ");
|
|
cmd.Parameters.Add(p_Id);
|
|
|
|
cmd.CommandText = sb.ToString();
|
|
|
|
|
|
_context.Database.OpenConnection();
|
|
MySqlDataAdapter da = new MySqlDataAdapter(cmd as MySqlCommand);
|
|
DataTable dt = new DataTable();
|
|
da.Fill(dt);
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
header = new
|
|
{
|
|
count = 0,
|
|
pass = 0,
|
|
notpass = 0
|
|
};
|
|
}
|
|
else
|
|
{
|
|
var dr = dt.Rows[0];
|
|
header = new
|
|
{
|
|
count = dr["count"].ToString().ToInteger(),
|
|
pass = dr["pass"].ToString().ToInteger(),
|
|
notpass = dr["notpass"].ToString().ToInteger()
|
|
};
|
|
}
|
|
}
|
|
var period = await _context.RecruitImports.AsQueryable()
|
|
.Select(x => new
|
|
{
|
|
x.Id,
|
|
Year = x.Year.ToThaiYear(),
|
|
x.Order,
|
|
x.Name,
|
|
})
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
return Success(new
|
|
{
|
|
data = data,
|
|
header = header,
|
|
period = period,
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
[HttpGet("exam/{id:length(36)}/{examId}")]
|
|
public async Task<ActionResult<ResponseObject>> GetExamResultByPersonAsync(Guid id, string examId)
|
|
{
|
|
try
|
|
{
|
|
var data = await _context.Recruits.AsQueryable()
|
|
.Include(x => x.RecruitImport)
|
|
.Include(x => x.Documents)
|
|
.ThenInclude(x => x.DocumentFile)
|
|
.Where(x => x.RecruitImport!.Id == id)
|
|
.Where(x => x.ExamId == examId)
|
|
.Join(_context.RecruitScores.AsQueryable()
|
|
.Include(x => x.ScoreImport),
|
|
rc => new { rc.RecruitImport!.Id, rc.ExamId },
|
|
sc => new { Id = sc.ScoreImport!.RecruitImportId, sc.ExamId },
|
|
(p, sr) => new
|
|
{
|
|
ExamID = p.ExamId,
|
|
ProfileID = p.CitizenId,
|
|
p.Prefix,
|
|
FullName = $"{p.FirstName} {p.LastName}",
|
|
DateOfBirth = p.DateOfBirth != null
|
|
? p.DateOfBirth != DateTime.MinValue
|
|
? p.DateOfBirth.ToThaiShortDate()
|
|
: ""
|
|
: "",
|
|
Gender = p.Gendor,
|
|
Degree = p.Educations.First().Degree,
|
|
Major = p.Educations.First().Major,
|
|
CertificateNo = p.Certificates.Count > 0
|
|
? p.Certificates.First().CertificateNo ?? ""
|
|
: "",
|
|
CertificateIssueDate = p.Certificates.Count > 0
|
|
? p.Certificates.First().IssueDate != DateTime.MinValue
|
|
? p.Certificates.First().IssueDate.ToThaiShortDate()
|
|
: ""
|
|
: "",
|
|
ExamResult = sr == null ? "" : sr.ExamStatus,
|
|
ExamAttribute = _recruitService.CheckValidCertificate(p.Certificates.First().IssueDate, 5) ? "มีคุณสมบัติ" : "ไม่มีคุณสมบัติ",
|
|
IsSpecial = p.Isspecial,
|
|
Remark = p.Remark,
|
|
University = p.Educations.First().University,
|
|
PositionName = p.PositionName,
|
|
PositionType = p.PositionType,
|
|
PositionLevel = p.PositionLevel,
|
|
ExamName = p.RecruitImport!.Name,
|
|
ExamOrder = p.RecruitImport.Order,
|
|
ExamYear = p.RecruitImport.Year.ToThaiYear(),
|
|
Score = sr == null ? 0.0 : sr.SumA + sr.SumB + sr.SumC,
|
|
Number = sr == null ? "" : sr.Number,
|
|
ExamCount = _recruitService.GetExamCount(p.CitizenId),
|
|
ScoreExpire = p.RecruitImport.AnnouncementDate == null
|
|
? ""
|
|
: p.RecruitImport.AnnouncementDate != DateTime.MinValue
|
|
? p.RecruitImport.AnnouncementDate.Value.AddYears(2).ToThaiShortDate()
|
|
: "",
|
|
typeTest = p.typeTest,
|
|
ScoreResult = sr == null ? null : new
|
|
{
|
|
ScoreAFull = sr.FullA,
|
|
ScoreA = sr.SumA,
|
|
ScoreBFull = sr.FullB,
|
|
ScoreB = sr.SumB,
|
|
ScoreAB = sr.SumAB,
|
|
ScoreCFull = sr.FullC,
|
|
ScoreC = sr.SumC,
|
|
ScoreDFull = sr.FullD,
|
|
ScoreD = sr.SumD,
|
|
ScoreCD = sr.SumCD,
|
|
ScoreSumFull = sr.FullScore,
|
|
ScoreSum = sr.TotalScore,
|
|
ExamResult = sr.ExamStatus
|
|
},
|
|
Attachments = p.Documents.Select(a => new
|
|
{
|
|
FileName = a.DocumentFile.FileName,
|
|
DocumentId = a.DocumentFile.Id
|
|
})
|
|
})
|
|
.FirstOrDefaultAsync();
|
|
|
|
return Success(data);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " For CMS "
|
|
|
|
[HttpGet("competitive")]
|
|
[AllowAnonymous]
|
|
public IActionResult GetPeriodForCMS([FromQuery] int limit = 0)
|
|
{
|
|
try
|
|
{
|
|
var this_year = DateTime.Now.Year.ToCeYear();
|
|
|
|
var periods = (from r in _context.RecruitImports.AsQueryable().Include(x => x.RecruitImages)
|
|
where r.Year == this_year
|
|
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();
|
|
|
|
|
|
//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();
|
|
|
|
|
|
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)
|
|
{
|
|
try
|
|
{
|
|
var periods = (from r in _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.RecruitDocuments)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.RecruitImages)
|
|
.ThenInclude(x => x.Document)
|
|
where r.Id == id
|
|
select new
|
|
{
|
|
id = r.Id,
|
|
title = $"{r.Name} ครั้งที่ {r.Order}/{r.Year.ToThaiYear()}",
|
|
detail = r.Detail,
|
|
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"),
|
|
start = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-mm-dd"),
|
|
end = 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"),
|
|
examDate = r.ExamDate == null ? "" : r.ExamDate.Value.ToString("yyyy-MM-dd"),
|
|
Images = r.RecruitImages.OrderBy(x => x.CreatedAt).Select(s => new
|
|
{
|
|
Title = s.Document.FileName,
|
|
Url = s.Document.Id.ToString("D")
|
|
}).ToList(),
|
|
Files = r.RecruitDocuments.OrderBy(x => x.CreatedAt).Select(s => new
|
|
{
|
|
Title = s.Document.FileName,
|
|
Url = s.Document.Id.ToString("D")
|
|
}).ToList(),
|
|
}).FirstOrDefault();
|
|
|
|
// re create image list
|
|
var new_image = new List<dynamic>();
|
|
foreach (var p in periods.Images)
|
|
{
|
|
new_image.Add(new
|
|
{
|
|
Title = p.Title,
|
|
Url = _minioService.GetFilePath(Guid.Parse(p.Url)).Result,
|
|
});
|
|
}
|
|
|
|
// re create doc list
|
|
var new_doc = new List<dynamic>();
|
|
foreach (var p in periods.Files)
|
|
{
|
|
new_doc.Add(new
|
|
{
|
|
Title = p.Title,
|
|
Url = _minioService.GetFilePath(Guid.Parse(p.Url)).Result,
|
|
});
|
|
}
|
|
|
|
var result = new
|
|
{
|
|
periods.id,
|
|
periods.title,
|
|
periods.detail,
|
|
periods.category,
|
|
periods.category_id,
|
|
periods.announcement_endDate,
|
|
periods.announcement_startDate,
|
|
periods.start,
|
|
periods.end,
|
|
periods.announcementExam,
|
|
periods.register_endDate,
|
|
periods.register_startDate,
|
|
periods.payment_endDate,
|
|
periods.payment_startDate,
|
|
periods.examDate,
|
|
images = new_image,
|
|
files = new_doc
|
|
};
|
|
|
|
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region " Export Excel "
|
|
|
|
[HttpGet("export/exam/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> ExportExamAsync(Guid id)
|
|
{
|
|
var data = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.Recruits)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (data == null)
|
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
|
|
|
var header = $"{data.Name} ครั้งที่ {data.Order}/{data.Year.ToThaiYear()}";
|
|
|
|
var recruits = data.Recruits
|
|
.OrderBy(x => x.ExamId)
|
|
.Select(x => new
|
|
{
|
|
ExamId = x.ExamId,
|
|
CitizenId = x.CitizenId,
|
|
Fullname = $"{x.Prefix}{x.FirstName} {x.LastName}",
|
|
PositionName = x.PositionName,
|
|
PositionType = x.PositionType,
|
|
PositionLevel = x.PositionLevel
|
|
})
|
|
.ToList();
|
|
|
|
var _data = new
|
|
{
|
|
template = "ExamList",
|
|
reportName = $"ExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}",
|
|
data = new
|
|
{
|
|
header = header,
|
|
data = recruits
|
|
}
|
|
};
|
|
return Success(_data);
|
|
}
|
|
|
|
[HttpGet("export/pass-exam/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> ExportPassExamAsync(Guid id)
|
|
{
|
|
var data = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.Recruits)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
var data_pass = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.Scores)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (data == null)
|
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
|
|
|
if (data_pass == null)
|
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
|
|
|
if (data_pass!.ScoreImport == null)
|
|
return Error(GlobalMessages.InvalidExamScore, StatusCodes.Status404NotFound);
|
|
|
|
var header = $"{data.Name} ครั้งที่ {data.Order}/{data.Year.ToThaiYear()}";
|
|
var result = (from r in data.Recruits.ToList()
|
|
join s in data_pass.ScoreImport.Scores.Where(x => x.AStatus == "ผ่าน").ToList() on r.ExamId equals s.ExamId
|
|
orderby s.SumA descending
|
|
select new
|
|
{
|
|
r.ExamId,
|
|
r.CitizenId,
|
|
Fullname = $"{r.Prefix}{r.FirstName} {r.LastName}",
|
|
s.FullA,
|
|
s.SumA,
|
|
s.AStatus,
|
|
|
|
}).ToList();
|
|
var _data = new
|
|
{
|
|
template = "PassAExamList",
|
|
reportName = $"PassAExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}",
|
|
data = new
|
|
{
|
|
header = header,
|
|
data = result
|
|
}
|
|
};
|
|
return Success(_data);
|
|
}
|
|
|
|
[HttpGet("export/pass/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> ExportPassExamResultAsync(Guid id)
|
|
{
|
|
var data = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.Recruits)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
var data_pass = await _context.RecruitImports.AsQueryable()
|
|
.Include(x => x.ScoreImport)
|
|
.ThenInclude(x => x.Scores)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (data == null)
|
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
|
|
|
if (data_pass == null)
|
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
|
|
|
var header = $"{data.Name} ครั้งที่ {data.Order}/{data.Year.ToThaiYear()}";
|
|
var result = (from r in data.Recruits.ToList()
|
|
join s in data_pass.ScoreImport.Scores.Where(x => x.ExamStatus == "ผ่าน").ToList() on r.ExamId equals s.ExamId
|
|
select new
|
|
{
|
|
r.ExamId,
|
|
r.CitizenId,
|
|
Fullname = $"{r.Prefix}{r.FirstName} {r.LastName}",
|
|
Full = s.FullScore != null ? s.FullScore : 0,
|
|
Sum = s.TotalScore != null ? s.TotalScore : 0,
|
|
Status = s.ExamStatus,
|
|
r.PositionName,
|
|
r.PositionType,
|
|
r.PositionLevel,
|
|
s.Number
|
|
}).ToList()
|
|
.OrderBy(x => x.PositionName)
|
|
.ThenByDescending(x => x.Sum)
|
|
.ToList();
|
|
var _data = new
|
|
{
|
|
template = "PassExamList",
|
|
reportName = $"PassExamList_{DateTime.Now.ToString("yyyyMMddHHmmss")}",
|
|
data = new
|
|
{
|
|
header = header,
|
|
data = result
|
|
}
|
|
};
|
|
return Success(_data);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Image and Document "
|
|
|
|
/// <summary>
|
|
/// Upload Image หรือ เอกสารในรอบการสอบ
|
|
/// </summary>
|
|
/// <param name="type">ประเภทเอกสาร</param>
|
|
/// <param name="importId">รหัสรอบสมัคร</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลรอบการสมัครสอบ และ คนสมัครสอบในรอบสำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("{type}/{importId:length(36)}"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> UpdateDocAsync(string type, Guid importId)
|
|
{
|
|
try
|
|
{
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
|
|
var files = Request.Form.Files;
|
|
if (type == "img")
|
|
{
|
|
await _recruitService.UpdateImageAsync(importId, files);
|
|
}
|
|
else
|
|
{
|
|
await _recruitService.UpdateDocAsync(importId, files);
|
|
}
|
|
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ลบ Image หรือ เอกสารในรอบการสอบ
|
|
/// </summary>
|
|
/// <param name="type">ประเภทเอกสาร</param>
|
|
/// <param name="docId">รหัสไฟล์</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpDelete("{type}/{docId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteDocAsync(string type, Guid docId)
|
|
{
|
|
try
|
|
{
|
|
if (type == "img")
|
|
{
|
|
await _recruitService.DeleteImageAsync(docId);
|
|
}
|
|
else
|
|
{
|
|
await _recruitService.DeleteDocAsync(docId);
|
|
}
|
|
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex, "ไม่สามารถลบไฟล์ได้");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// โอนคนแข่งขันไปบรรจุ
|
|
/// </summary>
|
|
/// <param name="examId">รหัสรอบสมัคร</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อโอนคนแข่งขันไปบรรจุสำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("placement/{examId:length(36)}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> UpdateAsyncRecruitToPlacement(Guid examId)
|
|
{
|
|
try
|
|
{
|
|
await _recruitService.UpdateAsyncRecruitToPlacement(examId);
|
|
return Success();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Report "
|
|
/// <summary>
|
|
/// รายงานจำนวนผู้เข้าสอบแข่งขันเพื่อบรรจุเข้ารับราชการเป็นข้าราชการ กทม. สามัญ
|
|
/// </summary>
|
|
/// <param name="year">ปีงบประมาณ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจำนวนผู้เข้าสอบแข่งขันเพื่อบรรจุเข้ารับราชการเป็นข้าราชการ กทม. สามัญสำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("report1"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> report1(string year)
|
|
{
|
|
try
|
|
{
|
|
var year_ = int.Parse(year) - 543;
|
|
List<ExamInfo> header = new List<ExamInfo>();
|
|
using (var cmd = _context.Database.GetDbConnection().CreateCommand())
|
|
{
|
|
var sb = new StringBuilder();
|
|
cmd.CommandTimeout = 0;
|
|
cmd.Parameters.Clear();
|
|
sb.Clear();
|
|
sb.Append(" SELECT * ");
|
|
sb.Append(" FROM exam_info ");
|
|
sb.Append(" Where score_year = @year");
|
|
sb.Append(" ORDER BY Position_name ASC");
|
|
cmd.CommandText = sb.ToString();
|
|
cmd.Parameters.Add(new MySqlParameter("@year", MySqlDbType.Int32) { Value = year_ });
|
|
_context.Database.OpenConnection();
|
|
using (var reader = cmd.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
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(),
|
|
};
|
|
|
|
header.Add(examInfo);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
var groupedResult = header
|
|
.GroupBy(x => new
|
|
{
|
|
x.PositionName,
|
|
x.PositionLevel,
|
|
x.PositionType,
|
|
x.Gender,
|
|
x.Age,
|
|
x.Degree
|
|
})
|
|
.Select(group => new
|
|
{
|
|
positionName = group.Key.PositionName,
|
|
positionLevel = group.Key.PositionLevel,
|
|
positionType = group.Key.PositionType,
|
|
gender = group.Key.Gender,
|
|
age = group.Key.Age.ToString().ToThaiNumber(),
|
|
degree = group.Key.Degree,
|
|
amount = group.Count().ToString().ToThaiNumber()
|
|
})
|
|
.ToList();
|
|
|
|
var result = new
|
|
{
|
|
template = "recruit-officer-pre",
|
|
reportName = "xlsx-report",
|
|
data = new
|
|
{
|
|
year = year.ToString().ToThaiNumber(),
|
|
date = DateTime.Now.ToThaiShortDateWithPrefix().ToThaiNumber(),
|
|
list = groupedResult
|
|
}
|
|
};
|
|
|
|
|
|
return Success(result);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// รายงานจำนวนผู้สอบผ่านแข่งขันเพื่อบรรจุเข้ารับราชการเป็นข้าราชการ กทม. สามัญ
|
|
/// </summary>
|
|
/// <param name="year">ปีงบประมาณ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจำนวนผู้สอบผ่านแข่งขันเพื่อบรรจุเข้ารับราชการเป็นข้าราชการ กทม. สามัญสำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("report2"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> report2(string year)
|
|
{
|
|
try
|
|
{
|
|
var year_ = int.Parse(year) - 543;
|
|
List<ExamInfo> header = new List<ExamInfo>();
|
|
using (var cmd = _context.Database.GetDbConnection().CreateCommand())
|
|
{
|
|
var sb = new StringBuilder();
|
|
cmd.CommandTimeout = 0;
|
|
cmd.Parameters.Clear();
|
|
sb.Clear();
|
|
sb.Append(" SELECT * ");
|
|
sb.Append(" FROM exam_info ");
|
|
sb.Append(" Where score_year = @year");
|
|
sb.Append(" AND result = 'ผ่าน'");
|
|
sb.Append(" ORDER BY Position_name ASC");
|
|
cmd.CommandText = sb.ToString();
|
|
cmd.Parameters.Add(new MySqlParameter("@year", MySqlDbType.Int32) { Value = year_ });
|
|
_context.Database.OpenConnection();
|
|
using (var reader = cmd.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
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()
|
|
};
|
|
|
|
header.Add(examInfo);
|
|
}
|
|
|
|
}
|
|
}
|
|
var groupedResult = header
|
|
.GroupBy(x => new
|
|
{
|
|
x.PositionName,
|
|
x.PositionLevel,
|
|
x.PositionType,
|
|
x.Gender,
|
|
x.Age,
|
|
x.Degree,
|
|
x.Result
|
|
})
|
|
.Select(group => new
|
|
{
|
|
positionName = group.Key.PositionName,
|
|
positionLevel = group.Key.PositionLevel,
|
|
positionType = group.Key.PositionType,
|
|
gender = group.Key.Gender,
|
|
age = group.Key.Age.ToString().ToThaiNumber(),
|
|
degree = group.Key.Degree,
|
|
result = group.Key.Result,
|
|
amount = group.Count().ToString().ToThaiNumber()
|
|
})
|
|
.ToList();
|
|
|
|
var result = new
|
|
{
|
|
template = "recruit-officer-pass",
|
|
reportName = "xlsx-report",
|
|
data = new
|
|
{
|
|
year = year.ToString().ToThaiNumber(),
|
|
date = DateTime.Now.ToThaiShortDateWithPrefix().ToThaiNumber(),
|
|
list = groupedResult
|
|
}
|
|
};
|
|
return Success(result);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ผลคะแนนผู้สมัครสอบ
|
|
/// </summary>
|
|
/// <param name="id">รหัสรอบการสอบแข่งขัน</param>
|
|
/// <param name="examId">เลขประจำตัวสอบ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจำนวนผู้สอบผ่านแข่งขันเพื่อบรรจุเข้ารับราชการเป็นข้าราชการ กทม. สามัญสำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("report/exam/{id:length(36)}/{examId}"), DisableRequestSizeLimit]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> GetReportExamResultByPersonAsync(Guid id, string examId)
|
|
{
|
|
try
|
|
{
|
|
var data = await _context.Recruits.AsQueryable()
|
|
.Include(x => x.RecruitImport)
|
|
.Where(x => x.RecruitImport!.Id == id)
|
|
.Where(x => x.ExamId == examId)
|
|
.Join(_context.RecruitScores.AsQueryable()
|
|
.Include(x => x.ScoreImport),
|
|
rc => new { rc.RecruitImport!.Id, rc.ExamId },
|
|
sc => new { Id = sc.ScoreImport!.RecruitImportId, sc.ExamId },
|
|
(p, sr) => new
|
|
{
|
|
ExamID = p.ExamId != null ? p.ExamId.ToThaiNumber() : "",
|
|
CitizenId = p.CitizenId != null ? p.CitizenId.ToThaiNumber() : "",
|
|
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
|
DateOfBirth = p.DateOfBirth != null
|
|
? p.DateOfBirth != DateTime.MinValue
|
|
? p.DateOfBirth.ToThaiShortDate().ToString().ToThaiNumber()
|
|
: ""
|
|
: "",
|
|
Gender = p.Gendor,
|
|
Degree = p.Educations.First().Degree,
|
|
Major = p.Educations.First().Major,
|
|
University = p.Educations.First().University,
|
|
PositionName = p.PositionName,
|
|
ExamName = $"{p.RecruitImport!.Name} ครั้งที่ {p.RecruitImport.Order}/{p.RecruitImport.Year.ToThaiYear()}".ToThaiNumber(),
|
|
|
|
ExamCount = _recruitService.GetExamCount(p.CitizenId).ToString().ToThaiNumber(),
|
|
type = p.typeTest == "bangkok" ? "กทม." : p.typeTest == "ocsc" ? "ก.พ." : "",
|
|
FA = sr.FullA != null ? sr.FullA.ToString().ToThaiNumber() : "",
|
|
SA = sr.SumA != null ? sr.SumA.ToString().ToThaiNumber() : "",
|
|
FC = sr.FullC != null ? sr.FullC.ToString().ToThaiNumber() : "",
|
|
SC = sr.SumC != null ? sr.SumC.ToString().ToThaiNumber() : "",
|
|
FD = sr.FullD != null ? sr.FullD.ToString().ToThaiNumber() : "",
|
|
SD = sr.SumD != null ? sr.SumD.ToString().ToThaiNumber() : "",
|
|
F = sr.FullScore != null ? sr.FullScore.ToString().ToThaiNumber() : "",
|
|
T = sr.TotalScore != null ? sr.TotalScore.ToString().ToThaiNumber() : "",
|
|
Result = sr.ExamStatus,
|
|
Number = sr.Number != null ? sr.Number.ToString().ToThaiNumber() : "",
|
|
Expire = p.RecruitImport.AnnouncementDate == null
|
|
? ""
|
|
: p.RecruitImport.AnnouncementDate != DateTime.MinValue
|
|
? p.RecruitImport.AnnouncementDate.Value.AddYears(2).ToThaiShortDate().ToString().ToThaiNumber()
|
|
: "",
|
|
})
|
|
.FirstOrDefaultAsync();
|
|
|
|
var result = new
|
|
{
|
|
template = "recruit-exam",
|
|
reportName = "recruit-exam",
|
|
data = data
|
|
};
|
|
return Success(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
}
|
|
} |