This commit is contained in:
parent
6ad83ecc53
commit
9bde6a9895
2 changed files with 250 additions and 41 deletions
|
|
@ -1000,6 +1000,16 @@ namespace BMA.EHR.Application.Repositories.Reports
|
||||||
r.FirstName,
|
r.FirstName,
|
||||||
r.LastName,
|
r.LastName,
|
||||||
r.Gender,
|
r.Gender,
|
||||||
|
r.Root,
|
||||||
|
r.RootId,
|
||||||
|
r.Child1,
|
||||||
|
r.Child1Id,
|
||||||
|
r.Child2,
|
||||||
|
r.Child2Id,
|
||||||
|
r.Child3,
|
||||||
|
r.Child3Id,
|
||||||
|
r.Child4,
|
||||||
|
r.Child4Id,
|
||||||
r.RequestInsignia.Id,
|
r.RequestInsignia.Id,
|
||||||
r.Request.OrganizationId
|
r.Request.OrganizationId
|
||||||
})
|
})
|
||||||
|
|
@ -1010,6 +1020,16 @@ namespace BMA.EHR.Application.Repositories.Reports
|
||||||
ProfileId = group.Key.ProfileId,
|
ProfileId = group.Key.ProfileId,
|
||||||
FullName = $"{group.Key.Prefix}{group.Key.FirstName} {group.Key.LastName}",
|
FullName = $"{group.Key.Prefix}{group.Key.FirstName} {group.Key.LastName}",
|
||||||
Gender = group.Key.Gender,
|
Gender = group.Key.Gender,
|
||||||
|
Root = group.Key.Root ?? "",
|
||||||
|
RootId = group.Key.RootId,
|
||||||
|
Child1 = group.Key.Child1 ?? "",
|
||||||
|
Child1Id = group.Key.Child1Id,
|
||||||
|
Child2 = group.Key.Child2 ?? "",
|
||||||
|
Child2Id = group.Key.Child2Id,
|
||||||
|
Child3 = group.Key.Child3 ?? "",
|
||||||
|
Child3Id = group.Key.Child3Id,
|
||||||
|
Child4 = group.Key.Child4 ?? "",
|
||||||
|
Child4Id = group.Key.Child4Id,
|
||||||
Male = group.Count(r => r.Gender == "Male"), // Count male entries
|
Male = group.Count(r => r.Gender == "Male"), // Count male entries
|
||||||
Female = group.Count(r => r.Gender == "Female"), // Count female entries
|
Female = group.Count(r => r.Gender == "Female"), // Count female entries
|
||||||
InsigniaId = group.Key.Id,
|
InsigniaId = group.Key.Id,
|
||||||
|
|
@ -1035,6 +1055,16 @@ namespace BMA.EHR.Application.Repositories.Reports
|
||||||
ProfileId = Guid.Parse("00000000-0000-0000-0000-000000000000"),
|
ProfileId = Guid.Parse("00000000-0000-0000-0000-000000000000"),
|
||||||
FullName = "",
|
FullName = "",
|
||||||
Gender = "",
|
Gender = "",
|
||||||
|
Root = "",
|
||||||
|
RootId = (Guid?)Guid.Parse("00000000-0000-0000-0000-000000000000"),
|
||||||
|
Child1 = "",
|
||||||
|
Child1Id = (Guid?)Guid.Parse("00000000-0000-0000-0000-000000000000"),
|
||||||
|
Child2 = "",
|
||||||
|
Child2Id = (Guid?)Guid.Parse("00000000-0000-0000-0000-000000000000"),
|
||||||
|
Child3 = "",
|
||||||
|
Child3Id = (Guid?)Guid.Parse("00000000-0000-0000-0000-000000000000"),
|
||||||
|
Child4 = "",
|
||||||
|
Child4Id = (Guid?)Guid.Parse("00000000-0000-0000-0000-000000000000"),
|
||||||
Male = 0,
|
Male = 0,
|
||||||
Female = 0,
|
Female = 0,
|
||||||
InsigniaId = ins.InsigniaId,
|
InsigniaId = ins.InsigniaId,
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
||||||
|
|
||||||
var data = await _repository.GetCoinReport(req.roundId, type, req.node, req.nodeId);
|
var data = await _repository.GetCoinReport(req.roundId, type, req.node, req.nodeId);
|
||||||
var yearInsignalPeriod = await _repository.GetYearInsigniaPeriod(req.roundId);
|
var yearInsignalPeriod = await _repository.GetYearInsigniaPeriod(req.roundId);
|
||||||
|
var yearLastTwoDigits = yearInsignalPeriod.Substring(yearInsignalPeriod.Length - 2);
|
||||||
|
|
||||||
var dataResult = new List<dynamic>();
|
var dataResult = new List<dynamic>();
|
||||||
var dataList = new List<dynamic>(data);
|
var dataList = new List<dynamic>(data);
|
||||||
|
|
@ -117,6 +118,16 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
||||||
InsigniaName = dataList[i].GetType().GetProperty("InsigniaName").GetValue(dataList[i]),
|
InsigniaName = dataList[i].GetType().GetProperty("InsigniaName").GetValue(dataList[i]),
|
||||||
FullName = dataList[i].GetType().GetProperty("FullName").GetValue(dataList[i]),
|
FullName = dataList[i].GetType().GetProperty("FullName").GetValue(dataList[i]),
|
||||||
InsigniaInitial = dataList[i].GetType().GetProperty("InsigniaInitial").GetValue(dataList[i]),
|
InsigniaInitial = dataList[i].GetType().GetProperty("InsigniaInitial").GetValue(dataList[i]),
|
||||||
|
Root = dataList[i].GetType().GetProperty("Root").GetValue(dataList[i]),
|
||||||
|
RootId = dataList[i].GetType().GetProperty("RootId").GetValue(dataList[i]),
|
||||||
|
Child1 = dataList[i].GetType().GetProperty("Child1").GetValue(dataList[i]),
|
||||||
|
Child1Id = dataList[i].GetType().GetProperty("Child1Id").GetValue(dataList[i]),
|
||||||
|
Child2 = dataList[i].GetType().GetProperty("Child2").GetValue(dataList[i]),
|
||||||
|
Child2Id = dataList[i].GetType().GetProperty("Child2Id").GetValue(dataList[i]),
|
||||||
|
Child3 = dataList[i].GetType().GetProperty("Child3").GetValue(dataList[i]),
|
||||||
|
Child3Id = dataList[i].GetType().GetProperty("Child3Id").GetValue(dataList[i]),
|
||||||
|
Child4 = dataList[i].GetType().GetProperty("Child4").GetValue(dataList[i]),
|
||||||
|
Child4Id = dataList[i].GetType().GetProperty("Child4Id").GetValue(dataList[i]),
|
||||||
Male = gender == "ชาย" ? 1 : 0,
|
Male = gender == "ชาย" ? 1 : 0,
|
||||||
Female = gender == "หญิง" ? 1 : 0,
|
Female = gender == "หญิง" ? 1 : 0,
|
||||||
});
|
});
|
||||||
|
|
@ -145,54 +156,221 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
||||||
var stop = 0;
|
var stop = 0;
|
||||||
var colLeft = 0;
|
var colLeft = 0;
|
||||||
var colRight = 0;
|
var colRight = 0;
|
||||||
for (int i = 0; i < detailList.Count / 2; i++)
|
var maxRow = Math.Max(left.Count(), right.Count());
|
||||||
{
|
|
||||||
if (InsigniaName != (string)left.ElementAt(i).GetType().GetProperty("InsigniaName").GetValue(left.ElementAt(i)))
|
for (int i = 0; i < maxRow; i++)
|
||||||
{
|
{
|
||||||
InsigniaName = (string)left.ElementAt(i).GetType().GetProperty("InsigniaName").GetValue(left.ElementAt(i));
|
var leftItem = i < left.Count() ? left.ElementAt(i) : null;
|
||||||
male = left.Count(x => x.Male == 1 && x.InsigniaName == InsigniaName) + right.Count(x => x.Male == 1 && x.InsigniaName == InsigniaName);
|
var rightItem = i < right.Count() ? right.ElementAt(i) : null;
|
||||||
female = left.Count(x => x.Female == 1 && x.InsigniaName == InsigniaName) + right.Count(x => x.Female == 1 && x.InsigniaName == InsigniaName);
|
|
||||||
var countGroup = detailList.Count(x => x.InsigniaName == InsigniaName);
|
// ข้ามถ้าไม่มีข้อมูลทั้งสองฝั่ง
|
||||||
var countGroupTemp = detailList.Count(x => x.InsigniaName == InsigniaName && x.FullName == "");
|
if (leftItem == null && rightItem == null)
|
||||||
start = i == 0 ? (mergeList.Count + 1) : (stop + 1);
|
continue;
|
||||||
stop = i == 0 ? (mergeList.Count) + (countGroup - countGroupTemp) : (countGroup - countGroupTemp) == 1 ? start : start + (countGroup - countGroupTemp);
|
|
||||||
range = countGroup - countGroupTemp != 1 ? $"{start} - {stop}" : $"{start}";
|
var insigniaName = leftItem != null
|
||||||
colLeft = start;
|
? leftItem.GetType().GetProperty("InsigniaName").GetValue(leftItem)
|
||||||
colRight = start + 25;
|
: rightItem.GetType().GetProperty("InsigniaName").GetValue(rightItem);
|
||||||
}
|
|
||||||
// ดึงข้อมูล NameLeft และ NameRight
|
male = detailList.Count(x => x.Male == 1 && x.InsigniaName == insigniaName);
|
||||||
var nameLeft = left.ElementAt(i).GetType().GetProperty("FullName").GetValue(left.ElementAt(i));
|
female = detailList.Count(x => x.Female == 1 && x.InsigniaName == insigniaName);
|
||||||
var nameRight = right.ElementAt(i).GetType().GetProperty("FullName").GetValue(right.ElementAt(i));
|
var countGroup = detailList.Count(x => x.InsigniaName == insigniaName);
|
||||||
|
var countGroupTemp = detailList.Count(x => x.InsigniaName == insigniaName && x.FullName == "");
|
||||||
|
|
||||||
|
start = mergeList.Count + 1;
|
||||||
|
stop = start + (countGroup - countGroupTemp) - 1;
|
||||||
|
range = (countGroup - countGroupTemp) != 1 ? $"{start} - {stop}" : $"{start}";
|
||||||
|
|
||||||
// ถ้าไม่มีทั้ง NameLeft และ NameRight ให้ข้ามไป
|
|
||||||
if (string.IsNullOrEmpty((string)nameLeft) && string.IsNullOrEmpty((string)nameRight))
|
|
||||||
{
|
|
||||||
continue; // ข้ามการทำงานของลูปในรอบนี้
|
|
||||||
}
|
|
||||||
mergeList.Add(new
|
mergeList.Add(new
|
||||||
{
|
{
|
||||||
row = mergeList.Count + 1,
|
ColLeft = colLeft > 0 ? colLeft.ToString().ToThaiNumber() : "",
|
||||||
ColLeft = colLeft.ToString().ToThaiNumber(),
|
NameLeft = leftItem?.GetType().GetProperty("FullName").GetValue(leftItem),
|
||||||
NameLeft = left.ElementAt(i).GetType().GetProperty("FullName").GetValue(left.ElementAt(i)),
|
RootLeft = leftItem?.GetType().GetProperty("Root").GetValue(leftItem),
|
||||||
ColRight = colRight.ToString().ToThaiNumber(),
|
Child1Left = leftItem?.GetType().GetProperty("Child1").GetValue(leftItem),
|
||||||
NameRight = right.ElementAt(i).GetType().GetProperty("FullName").GetValue(right.ElementAt(i)),
|
Child2Left = leftItem?.GetType().GetProperty("Child2").GetValue(leftItem),
|
||||||
InsigniaInitial = left.ElementAt(i).GetType().GetProperty("InsigniaInitial").GetValue(left.ElementAt(i)),
|
Child3Left = leftItem?.GetType().GetProperty("Child3").GetValue(leftItem),
|
||||||
InsigniaName = left.ElementAt(i).GetType().GetProperty("InsigniaName").GetValue(left.ElementAt(i)),
|
Child4Left = leftItem?.GetType().GetProperty("Child4").GetValue(leftItem),
|
||||||
|
|
||||||
|
ColRight = colRight > 0 ? colRight.ToString().ToThaiNumber() : "",
|
||||||
|
NameRight = rightItem?.GetType().GetProperty("FullName").GetValue(rightItem),
|
||||||
|
RootRight = rightItem?.GetType().GetProperty("Root").GetValue(rightItem),
|
||||||
|
Child1Right = rightItem?.GetType().GetProperty("Child1").GetValue(rightItem),
|
||||||
|
Child2Right = rightItem?.GetType().GetProperty("Child2").GetValue(rightItem),
|
||||||
|
Child3Right = rightItem?.GetType().GetProperty("Child3").GetValue(rightItem),
|
||||||
|
Child4Right = rightItem?.GetType().GetProperty("Child4").GetValue(rightItem),
|
||||||
|
|
||||||
|
InsigniaInitial = leftItem?.GetType().GetProperty("InsigniaInitial").GetValue(leftItem)
|
||||||
|
?? rightItem?.GetType().GetProperty("InsigniaInitial").GetValue(rightItem),
|
||||||
|
InsigniaName = insigniaName,
|
||||||
Range = range.ToThaiNumber(),
|
Range = range.ToThaiNumber(),
|
||||||
Male = male.ToString().ToThaiNumber(),
|
Male = male.ToString().ToThaiNumber(),
|
||||||
Female = female.ToString().ToThaiNumber(),
|
Female = female.ToString().ToThaiNumber()
|
||||||
});
|
});
|
||||||
if (mergeList.Count % 25 == 0)
|
|
||||||
{
|
|
||||||
colLeft = colRight;
|
|
||||||
colRight = colLeft + 25;
|
|
||||||
}
|
|
||||||
colLeft++;
|
|
||||||
colRight++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dataResult = mergeList;
|
dataResult = mergeList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var groupedByOrg = detailList
|
||||||
|
.GroupBy(x =>
|
||||||
|
{
|
||||||
|
string child4Id = x.Child4Id?.ToString() ?? "";
|
||||||
|
string child3Id = x.Child3Id?.ToString() ?? "";
|
||||||
|
string child2Id = x.Child2Id?.ToString() ?? "";
|
||||||
|
string child1Id = x.Child1Id?.ToString() ?? "";
|
||||||
|
string rootId = x.RootId?.ToString() ?? "";
|
||||||
|
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(child4Id)) return child4Id;
|
||||||
|
if (!string.IsNullOrEmpty(child3Id)) return child3Id;
|
||||||
|
if (!string.IsNullOrEmpty(child2Id)) return child2Id;
|
||||||
|
if (!string.IsNullOrEmpty(child1Id)) return child1Id;
|
||||||
|
return rootId;
|
||||||
|
})
|
||||||
|
.Where(g => !string.IsNullOrWhiteSpace(g.Key))
|
||||||
|
.Select(orgGroup =>
|
||||||
|
{
|
||||||
|
var first = orgGroup.FirstOrDefault();
|
||||||
|
|
||||||
|
var org = !string.IsNullOrWhiteSpace(first?.Child4) ? first.Child4.Trim() :
|
||||||
|
!string.IsNullOrWhiteSpace(first?.Child3) ? first.Child3.Trim() :
|
||||||
|
!string.IsNullOrWhiteSpace(first?.Child2) ? first.Child2.Trim() :
|
||||||
|
!string.IsNullOrWhiteSpace(first?.Child1) ? first.Child1.Trim() :
|
||||||
|
first.Root.Trim();
|
||||||
|
|
||||||
|
// Group by InsigniaName
|
||||||
|
var groupedByInsignia = orgGroup
|
||||||
|
.GroupBy(x => x.InsigniaName)
|
||||||
|
.Select(insigniaGroup =>
|
||||||
|
{
|
||||||
|
if (!insigniaGroup.Any(x => !string.IsNullOrWhiteSpace(x.FullName)))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var insigniaName = insigniaGroup.Key;
|
||||||
|
var left = insigniaGroup.Where(x => x.status == false).ToList();
|
||||||
|
var right = insigniaGroup.Where(x => x.status == true).ToList();
|
||||||
|
|
||||||
|
var male = insigniaGroup.Count(x => x.Male == 1);
|
||||||
|
var female = insigniaGroup.Count(x => x.Female == 1);
|
||||||
|
var countGroup = insigniaGroup.Count();
|
||||||
|
var countGroupTemp = insigniaGroup.Count(x => x.FullName == "");
|
||||||
|
|
||||||
|
var start = 1;
|
||||||
|
var stop = countGroup - countGroupTemp;
|
||||||
|
var range = stop == 1 ? $"{start}" : $"{start} - {stop}";
|
||||||
|
range = range.ToThaiNumber();
|
||||||
|
|
||||||
|
var people = new List<object>();
|
||||||
|
|
||||||
|
int colLeft = 1;
|
||||||
|
int colRight = 26;
|
||||||
|
int rowCount = Math.Max(left.Count, right.Count);
|
||||||
|
|
||||||
|
var allPeople = left.Concat(right).ToList();
|
||||||
|
|
||||||
|
int colLeftStart = 1;
|
||||||
|
int colRightStart = 26;
|
||||||
|
|
||||||
|
for (int i = 0; i < allPeople.Count; i++)
|
||||||
|
{
|
||||||
|
var person = allPeople[i];
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(person?.FullName))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (i < 25)
|
||||||
|
{
|
||||||
|
people.Add(new
|
||||||
|
{
|
||||||
|
ColLeft = colLeftStart.ToString().ToThaiNumber(),
|
||||||
|
NameLeft = person.FullName,
|
||||||
|
RootLeft = person.Root,
|
||||||
|
Child1Left = person.Child1,
|
||||||
|
Child2Left = person.Child2,
|
||||||
|
Child3Left = person.Child3,
|
||||||
|
Child4Left = person.Child4,
|
||||||
|
|
||||||
|
ColRight = "",
|
||||||
|
NameRight = "",
|
||||||
|
RootRight = "",
|
||||||
|
Child1Right = "",
|
||||||
|
Child2Right = "",
|
||||||
|
Child3Right = "",
|
||||||
|
Child4Right = "",
|
||||||
|
|
||||||
|
InsigniaInitial = person.InsigniaInitial,
|
||||||
|
InsigniaName = insigniaName,
|
||||||
|
Range = range,
|
||||||
|
Male = male.ToString().ToThaiNumber(),
|
||||||
|
Female = female.ToString().ToThaiNumber()
|
||||||
|
});
|
||||||
|
|
||||||
|
colLeftStart++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// คำนวณแถวที่จะเอาข้อมูลขวาไปใส่
|
||||||
|
int indexToUpdate = i - 25; // ถ้า i=25 จะไปแถว 0, i=26 ไปแถว 1 เป็นต้น
|
||||||
|
|
||||||
|
// ดึงแถวที่ต้องการมาแก้ไข
|
||||||
|
var row = (dynamic)people[indexToUpdate];
|
||||||
|
|
||||||
|
// สร้าง object ใหม่โดยคัดลอกข้อมูลซ้ายเดิมและเพิ่มข้อมูลขวา
|
||||||
|
var updatedRow = new
|
||||||
|
{
|
||||||
|
ColLeft = row.ColLeft,
|
||||||
|
NameLeft = row.NameLeft,
|
||||||
|
RootLeft = row.RootLeft,
|
||||||
|
Child1Left = row.Child1Left,
|
||||||
|
Child2Left = row.Child2Left,
|
||||||
|
Child3Left = row.Child3Left,
|
||||||
|
Child4Left = row.Child4Left,
|
||||||
|
|
||||||
|
ColRight = colRightStart.ToString().ToThaiNumber(),
|
||||||
|
NameRight = person.FullName,
|
||||||
|
RootRight = person.Root,
|
||||||
|
Child1Right = person.Child1,
|
||||||
|
Child2Right = person.Child2,
|
||||||
|
Child3Right = person.Child3,
|
||||||
|
Child4Right = person.Child4,
|
||||||
|
|
||||||
|
InsigniaInitial = person.InsigniaInitial,
|
||||||
|
InsigniaName = insigniaName,
|
||||||
|
Range = range,
|
||||||
|
Male = male.ToString().ToThaiNumber(),
|
||||||
|
Female = female.ToString().ToThaiNumber()
|
||||||
|
};
|
||||||
|
|
||||||
|
// แทนที่แถวเดิมด้วยแถวที่อัพเดต
|
||||||
|
people[indexToUpdate] = updatedRow;
|
||||||
|
|
||||||
|
colRightStart++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
name = $"(ชั้นตรา) {insigniaName}",
|
||||||
|
shotName = left.FirstOrDefault()?.InsigniaInitial ?? right.FirstOrDefault()?.InsigniaInitial,
|
||||||
|
range = range,
|
||||||
|
male = male.ToString().ToThaiNumber(),
|
||||||
|
female = female.ToString().ToThaiNumber(),
|
||||||
|
people = people
|
||||||
|
};
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
org = org,
|
||||||
|
insignia = groupedByInsignia
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.Where(x => !string.IsNullOrWhiteSpace(x.org) && x.insignia.Any())
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var result = new
|
var result = new
|
||||||
{
|
{
|
||||||
template = "reportInsignia1",
|
template = "reportInsignia1",
|
||||||
|
|
@ -200,7 +378,8 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
||||||
data = new
|
data = new
|
||||||
{
|
{
|
||||||
yearInsignalPeriod = yearInsignalPeriod,
|
yearInsignalPeriod = yearInsignalPeriod,
|
||||||
data = dataResult,
|
yearLastTwoDigits = yearLastTwoDigits,
|
||||||
|
data = groupedByOrg,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Success(result);
|
return Success(result);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue