This commit is contained in:
Bright 2025-09-02 18:06:00 +07:00
parent f5f4115ef0
commit 8a3df45c03
5 changed files with 1831 additions and 21 deletions

View file

@ -641,7 +641,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
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,
})
@ -1089,6 +1089,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
r.CitizenCardExpireDate = Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-"));
r.ApplyDate = (DateTime)workSheet?.Cells[row, 9999]?.GetValue<DateTime>();
r.PositionName = workSheet?.Cells[row, 3]?.GetValue<string>() ?? "";
r.HddPosition = workSheet?.Cells[row, 4]?.GetValue<string>() ?? "";
r.PositionType = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
r.PositionLevel = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "";
r.CreatedAt = DateTime.Now;
@ -1237,8 +1238,20 @@ namespace BMA.EHR.Recruit.Service.Controllers
#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");
@ -1295,6 +1308,9 @@ namespace BMA.EHR.Recruit.Service.Controllers
CreatedAt = DateTime.Now,
CreatedUserId = UserId ?? "",
CreatedFullName = FullName ?? "System Administrator",
LastUpdatedAt = DateTime.Now,
LastUpdateUserId = UserId ?? "",
LastUpdateFullName = FullName ?? "System Administrator",
});
// create new file import
@ -1302,6 +1318,12 @@ namespace BMA.EHR.Recruit.Service.Controllers
{
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>()
};
@ -1310,7 +1332,6 @@ namespace BMA.EHR.Recruit.Service.Controllers
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];
@ -1325,30 +1346,85 @@ namespace BMA.EHR.Recruit.Service.Controllers
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>();
r.CitizenId = workSheet?.Cells[row, 3]?.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.FullA = 200;
r.SumA = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 5]?.GetValue<string>()) ? 0.00 : (double)workSheet?.Cells[row, 5]?.GetValue<double>();
r.PercentageA = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 6]?.GetValue<string>()) ? 0.00 : (double)workSheet?.Cells[row, 6]?.GetValue<double>();
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 : (double)workSheet?.Cells[row, 5]?.GetValue<double>();
r.ABStatus = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 7]?.GetValue<string>()) ? "" : workSheet?.Cells[row, 7]?.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.FullC = 50;
r.SumC = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 8]?.GetValue<string>()) ? 0.00 : (double)workSheet?.Cells[row, 8]?.GetValue<double>();
r.FullD = 50;
r.SumD = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 9]?.GetValue<string>()) ? 0.00 : (double)workSheet?.Cells[row, 9]?.GetValue<double>();
r.SumCD = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 10]?.GetValue<string>()) ? 0.00 : (double)workSheet?.Cells[row, 10]?.GetValue<double>();
r.PercentageC = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 11]?.GetValue<string>()) ? 0.00 : (double)workSheet?.Cells[row, 11]?.GetValue<double>();
r.CStatus = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 12]?.GetValue<string>()) ? "" : workSheet?.Cells[row, 12]?.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.FullScore = 300;
r.TotalScore = string.IsNullOrWhiteSpace(workSheet?.Cells[row, 13]?.GetValue<string>()) ? 0.00 : (double)workSheet?.Cells[row, 13]?.GetValue<double>(); ;
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>();
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.ExamStatus = workSheet?.Cells[row, 24]?.GetValue<string>();
r.Number = workSheet?.Cells[row, 25]?.GetValue<string>() ?? "";
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++;
@ -1399,6 +1475,93 @@ namespace BMA.EHR.Recruit.Service.Controllers
#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);
var file = Request.Form.Files[0];
using (var stream = file.OpenReadStream())
using (var c_package = new ExcelPackage(stream))
{
var score = rec_import.ScoreImport.Scores
.Where(s => !string.IsNullOrEmpty(s.ExamId))
.ToDictionary(s => s.ExamId, s => s);
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>
@ -1504,6 +1667,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
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(),
position_level = dr["position_level"].ToString(),
position_type = dr["position_type"].ToString(),
exam_name = dr["exam_name"].ToString(),

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,50 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Recruit.Service.Migrations
{
/// <inheritdoc />
public partial class update_field_RecruitScorebstatus : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "BStatus",
table: "RecruitScores",
type: "varchar(50)",
maxLength: 50,
nullable: true,
oldClrType: typeof(string),
oldType: "varchar(50)",
oldMaxLength: 50)
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
table: "RecruitScores",
keyColumn: "BStatus",
keyValue: null,
column: "BStatus",
value: "");
migrationBuilder.AlterColumn<string>(
name: "BStatus",
table: "RecruitScores",
type: "varchar(50)",
maxLength: 50,
nullable: false,
oldClrType: typeof(string),
oldType: "varchar(50)",
oldMaxLength: 50,
oldNullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
}
}
}

View file

@ -1162,7 +1162,6 @@ namespace BMA.EHR.Recruit.Service.Migrations
.HasComment("ภาคความรู้ความสามารถที่ใช้เฉพาะตำแหน่ง ผลประเมิน");
b.Property<string>("BStatus")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("varchar(50)");

View file

@ -27,7 +27,7 @@ namespace BMA.EHR.Recruit.Service.Models.Recruits
public double? PercentageB { get; set; }
[MaxLength(50)]
public string BStatus { get; set; }
public string? BStatus { get; set; }
[Comment("ภาคความรู้ความสามารถที่ใช้เฉพาะตำแหน่ง คะแนนรวม")]
public double SumAB { get; set; }