Fix รายงานใบสมัครสอบส่วนเนื้อหาคำรับรองเพี้ยน #2099
This commit is contained in:
parent
f78d188979
commit
27112a060c
1 changed files with 32 additions and 13 deletions
|
|
@ -94,21 +94,40 @@ namespace BMA.EHR.Application.Repositories.Reports
|
||||||
if (candidate == null)
|
if (candidate == null)
|
||||||
throw new Exception(GlobalMessages.CandidateNotFound);
|
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||||
|
|
||||||
var editorConfirmLists = string.IsNullOrEmpty(candidate.PeriodExam?.EditorConfirm)
|
List<string> editorConfirmLists;
|
||||||
? new List<string>
|
|
||||||
|
var textOnly = string.IsNullOrEmpty(candidate.PeriodExam?.EditorConfirm)
|
||||||
|
? null
|
||||||
|
: Regex.Replace(
|
||||||
|
candidate.PeriodExam.EditorConfirm,
|
||||||
|
"<[^>]+>",
|
||||||
|
string.Empty
|
||||||
|
)
|
||||||
|
.Replace(" ", " ")
|
||||||
|
.Trim();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(textOnly))
|
||||||
|
{
|
||||||
|
// ลบข้อความทั้งหมดก่อน "1." เพื่อให้เริ่มต้นที่ข้อแรกเสมอ
|
||||||
|
var cleanedText = Regex.Replace(textOnly, @"^.*?1\.", "1.").Trim();
|
||||||
|
|
||||||
|
// ถ้าข้อ 3 จบด้วย "มาตรา 1374." แล้วเลข 4. ติดกับประโยค ให้แทรกขึ้นบรรทัดใหม่เป็นข้อ 4.
|
||||||
|
if (!cleanedText.Contains("\n4.") && Regex.IsMatch(cleanedText, @"1374\.\s*"))
|
||||||
{
|
{
|
||||||
"-"
|
cleanedText = Regex.Replace(cleanedText, @"1374\.\s*", "137\n4. ");
|
||||||
}
|
}
|
||||||
: Regex.Matches(
|
|
||||||
Regex.Replace(candidate.PeriodExam.EditorConfirm, "<.*?>", string.Empty)
|
// แยกข้อความเป็นแต่ละข้อ โดย split เมื่อเจอ pattern "ตัวเลข. "
|
||||||
.Replace(" ", " ")
|
// ใช้ lookahead (?=...) เพื่อไม่กินตัวเลขทิ้ง และให้ตัวเลขยังอยู่ในผลลัพธ์
|
||||||
.Trim(),
|
editorConfirmLists = Regex.Split(cleanedText, @"(?=\d+\. )")
|
||||||
@"[1-9]\.\s*(.*?)(?=[1-9]\.|$)", // ตอนนี้ Fix ไว้ให้กรอกเลขลำดับตามด้วย .เท่านั้น เช่น 1. 2. 3. และรองรับได้สูงสุดแค่ 1-9 เท่านั้น
|
.Where(s => !string.IsNullOrWhiteSpace(s))
|
||||||
RegexOptions.Singleline
|
.Select(s => s.Replace("\n", "").Replace("\r", "").Trim())
|
||||||
)
|
.ToList();
|
||||||
.Cast<Match>()
|
}
|
||||||
.Select((m, index) => $"{index + 1}. {m.Groups[1].Value.Trim()}") // สร้างหมายเลขข้อจาก Index
|
else
|
||||||
.ToList();
|
{
|
||||||
|
editorConfirmLists = new List<string> { "-" };
|
||||||
|
}
|
||||||
|
|
||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue