report discipline

This commit is contained in:
moss 2025-04-17 18:05:42 +07:00
parent 7db251aea9
commit 864c348531
4 changed files with 3901 additions and 33 deletions

View file

@ -89,21 +89,149 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
// profile = profile.Where(x => x.PositionType == req.posType || x.PositionLevel == req.posLevel).ToList();
//}
var data_search = await _context.DisciplineDisciplinarys
.Include(x => x.DisciplineDisciplinary_ProfileComplaintInvestigates)
var data_search1 = await _context.DisciplineComplaints
.Include(x => x.DisciplineComplaint_Profiles)
.Where(x => req.status.Trim().ToUpper() == "ALL" ? true : (x.Status != null && x.Status.Contains(req.status.Trim().ToUpper())))
.Where(x => req.offenseDetail.Trim().ToUpper() == "ALL" ? true : (x.OffenseDetails != null && x.OffenseDetails.Contains(req.status.Trim().ToUpper())))
// .Where(x => req.disciplinaryFaultLevel.Trim().ToUpper() == "ALL" ? true : (x.DisciplinaryFaultLevel != null && x.DisciplinaryFaultLevel.Contains(req.status.Trim().ToUpper())))
.OrderByDescending(x => x.CreatedAt)
.ToListAsync();
if (req.status.Trim().ToUpper() != "ALL")
data_search = data_search.Where(x => x.Status != null && x.Status.Contains(req.status.Trim().ToUpper())).ToList();
var mapData1 = data_search1
.SelectMany((d) => d.DisciplineComplaint_Profiles.Select((profile) => new
{
fullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}",
citizenId = profile.CitizenId,
position = profile.Position,
posLevel = profile.posLevelName,
oc = profile.Organization,
CreatedAt = profile.CreatedAt,
offense = d.OffenseDetails != null && d.OffenseDetails != ""
? d.OffenseDetails == "NOT_SPECIFIED"
? "ความผิดวินัยยังไม่ระบุ"
: d.OffenseDetails == "NOT_DEADLY"
? "ความผิดวินัยไม่ร้ายแรง"
: d.OffenseDetails == "DEADLY"
? "ความผิดวินัยร้ายแรง"
: ""
: "",
faultLevel = "",
Child4Id = profile.child4DnaId,
Child4 = profile.child4,
Child3Id = profile.child3DnaId,
Child3 = profile.child3,
Child2Id = profile.child2DnaId,
Child2 = profile.child2,
Child1Id = profile.child1DnaId,
Child1 = profile.child1,
RootId = profile.rootDnaId,
Root = profile.root,
PosType = profile.posTypeName,
PosLevel = profile.posLevelName
}))
.Where(x => req.node == 4 ? x.Child4Id == req.nodeId : (req.node == 3 ? x.Child3Id == req.nodeId : (req.node == 2 ? x.Child2Id == req.nodeId : (req.node == 1 ? x.Child1Id == req.nodeId : (req.node == 0 ? x.RootId == req.nodeId : (req.node == null ? true : true))))))
.Where(x => jsonData["result"] == "OWNER" || jsonData["result"] == "CHILD" ? true : (req.node == 0 ? x.Child1Id == null : (req.node == 1 ? x.Child2Id == null : (req.node == 2 ? x.Child3Id == null : (req.node == 3 ? x.Child4Id == null : true)))))
.Where(x => string.IsNullOrEmpty(req.posType) || x.PosType == req.posType)
.Where(x => string.IsNullOrEmpty(req.posLevel) || x.PosLevel == req.posLevel)
.OrderByDescending(x => x.CreatedAt)
.ToList();
var groupedResult1 = mapData1
.GroupBy(x => x.fullName)
.Select(g => new
{
one = g.Count(), // Count of records per fullName
two = 0,
three = 0,
g.Where(x => x.fullName != null || x.fullName != "").FirstOrDefault()?.fullName,
g.Where(x => x.citizenId != null || x.citizenId != "").FirstOrDefault()?.citizenId,
g.Where(x => x.position != null || x.position != "").FirstOrDefault()?.position,
g.Where(x => x.posLevel != null || x.posLevel != "").FirstOrDefault()?.posLevel,
oc = (g.Where(x => x.Child4 != null || x.Child4 != "").FirstOrDefault()?.Child4 == null ? "" : g.Where(x => x.Child4 != null || x.Child4 != "").FirstOrDefault()?.Child4 + "\n") +
(g.Where(x => x.Child3 != null || x.Child3 != "").FirstOrDefault()?.Child3 == null ? "" : g.Where(x => x.Child3 != null || x.Child3 != "").FirstOrDefault()?.Child3 + "\n") +
(g.Where(x => x.Child2 != null || x.Child2 != "").FirstOrDefault()?.Child2 == null ? "" : g.Where(x => x.Child2 != null || x.Child2 != "").FirstOrDefault()?.Child2 + "\n") +
(g.Where(x => x.Child1 != null || x.Child1 != "").FirstOrDefault()?.Child1 == null ? "" : g.Where(x => x.Child1 != null || x.Child1 != "").FirstOrDefault()?.Child1 + "\n") +
(g.Where(x => x.Root != null || x.Root != "").FirstOrDefault()?.Root == null ? "" : g.Where(x => x.Root != null || x.Root != "").FirstOrDefault()?.Root),
g.Where(x => x.offense != null || x.offense != "").FirstOrDefault()?.offense,
g.Where(x => x.faultLevel != null || x.faultLevel != "").FirstOrDefault()?.faultLevel,
})
.ToList();
if (req.offenseDetail.Trim().ToUpper() != "ALL")
data_search = data_search.Where(x => x.OffenseDetails != null && x.OffenseDetails.Contains(req.status.Trim().ToUpper())).ToList();
var data_search2 = await _context.DisciplineInvestigates
.Include(x => x.DisciplineInvestigate_ProfileComplaints)
.Where(x => req.status.Trim().ToUpper() == "ALL" ? true : (x.Status != null && x.Status.Contains(req.status.Trim().ToUpper())))
.Where(x => req.offenseDetail.Trim().ToUpper() == "ALL" ? true : (x.OffenseDetails != null && x.OffenseDetails.Contains(req.status.Trim().ToUpper())))
// .Where(x => req.disciplinaryFaultLevel.Trim().ToUpper() == "ALL" ? true : (x.DisciplinaryFaultLevel != null && x.DisciplinaryFaultLevel.Contains(req.status.Trim().ToUpper())))
.OrderByDescending(x => x.CreatedAt)
.ToListAsync();
if (req.disciplinaryFaultLevel.Trim().ToUpper() != "ALL")
data_search = data_search.Where(x => x.DisciplinaryFaultLevel != null && x.DisciplinaryFaultLevel.Contains(req.status.Trim().ToUpper())).ToList();
var mapData2 = data_search2
.SelectMany((d) => d.DisciplineInvestigate_ProfileComplaints.Select((profile) => new
{
fullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}",
citizenId = profile.CitizenId,
position = profile.Position,
posLevel = profile.posLevelName,
oc = profile.Organization,
CreatedAt = profile.CreatedAt,
offense = d.OffenseDetails != null && d.OffenseDetails != ""
? d.OffenseDetails == "NOT_SPECIFIED"
? "ความผิดวินัยยังไม่ระบุ"
: d.OffenseDetails == "NOT_DEADLY"
? "ความผิดวินัยไม่ร้ายแรง"
: d.OffenseDetails == "DEADLY"
? "ความผิดวินัยร้ายแรง"
: ""
: "",
faultLevel = "",
Child4Id = profile.child4DnaId,
Child4 = profile.child4,
Child3Id = profile.child3DnaId,
Child3 = profile.child3,
Child2Id = profile.child2DnaId,
Child2 = profile.child2,
Child1Id = profile.child1DnaId,
Child1 = profile.child1,
RootId = profile.rootDnaId,
Root = profile.root,
PosType = profile.posTypeName,
PosLevel = profile.posLevelName
}))
.Where(x => req.node == 4 ? x.Child4Id == req.nodeId : (req.node == 3 ? x.Child3Id == req.nodeId : (req.node == 2 ? x.Child2Id == req.nodeId : (req.node == 1 ? x.Child1Id == req.nodeId : (req.node == 0 ? x.RootId == req.nodeId : (req.node == null ? true : true))))))
.Where(x => jsonData["result"] == "OWNER" || jsonData["result"] == "CHILD" ? true : (req.node == 0 ? x.Child1Id == null : (req.node == 1 ? x.Child2Id == null : (req.node == 2 ? x.Child3Id == null : (req.node == 3 ? x.Child4Id == null : true)))))
.Where(x => string.IsNullOrEmpty(req.posType) || x.PosType == req.posType)
.Where(x => string.IsNullOrEmpty(req.posLevel) || x.PosLevel == req.posLevel)
.OrderByDescending(x => x.CreatedAt)
.ToList();
var groupedResult2 = mapData2
.GroupBy(x => x.fullName)
.Select(g => new
{
one = 0,
two = g.Count(), // Count of records per fullName
three = 0,
g.Where(x => x.fullName != null || x.fullName != "").FirstOrDefault()?.fullName,
g.Where(x => x.citizenId != null || x.citizenId != "").FirstOrDefault()?.citizenId,
g.Where(x => x.position != null || x.position != "").FirstOrDefault()?.position,
g.Where(x => x.posLevel != null || x.posLevel != "").FirstOrDefault()?.posLevel,
oc = (g.Where(x => x.Child4 != null || x.Child4 != "").FirstOrDefault()?.Child4 == null ? "" : g.Where(x => x.Child4 != null || x.Child4 != "").FirstOrDefault()?.Child4 + "\n") +
(g.Where(x => x.Child3 != null || x.Child3 != "").FirstOrDefault()?.Child3 == null ? "" : g.Where(x => x.Child3 != null || x.Child3 != "").FirstOrDefault()?.Child3 + "\n") +
(g.Where(x => x.Child2 != null || x.Child2 != "").FirstOrDefault()?.Child2 == null ? "" : g.Where(x => x.Child2 != null || x.Child2 != "").FirstOrDefault()?.Child2 + "\n") +
(g.Where(x => x.Child1 != null || x.Child1 != "").FirstOrDefault()?.Child1 == null ? "" : g.Where(x => x.Child1 != null || x.Child1 != "").FirstOrDefault()?.Child1 + "\n") +
(g.Where(x => x.Root != null || x.Root != "").FirstOrDefault()?.Root == null ? "" : g.Where(x => x.Root != null || x.Root != "").FirstOrDefault()?.Root),
g.Where(x => x.offense != null || x.offense != "").FirstOrDefault()?.offense,
g.Where(x => x.faultLevel != null || x.faultLevel != "").FirstOrDefault()?.faultLevel,
})
.ToList();
var mapData = data_search
var data_search3 = await _context.DisciplineDisciplinarys
.Include(x => x.DisciplineDisciplinary_ProfileComplaintInvestigates)
.Where(x => req.status.Trim().ToUpper() == "ALL" ? true : (x.Status != null && x.Status.Contains(req.status.Trim().ToUpper())))
.Where(x => req.offenseDetail.Trim().ToUpper() == "ALL" ? true : (x.OffenseDetails != null && x.OffenseDetails.Contains(req.status.Trim().ToUpper())))
.Where(x => req.disciplinaryFaultLevel.Trim().ToUpper() == "ALL" ? true : (x.DisciplinaryFaultLevel != null && x.DisciplinaryFaultLevel.Contains(req.status.Trim().ToUpper())))
.OrderByDescending(x => x.CreatedAt)
.ToListAsync();
var mapData3 = data_search3
.SelectMany((d) => d.DisciplineDisciplinary_ProfileComplaintInvestigates.Select((profile) => new
{
fullName = $"{profile.Prefix}{profile.FirstName} {profile.LastName}",
@ -122,31 +250,68 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
: ""
: "",
faultLevel = d.DisciplinaryFaultLevel,
Child4Id = profile.child4Id,
Child4Id = profile.child4DnaId,
Child4 = profile.child4,
Child3Id = profile.child3Id,
Child3Id = profile.child3DnaId,
Child3 = profile.child3,
Child2Id = profile.child2Id,
Child2Id = profile.child2DnaId,
Child2 = profile.child2,
Child1Id = profile.child1Id,
Child1Id = profile.child1DnaId,
Child1 = profile.child1,
RootId = profile.rootId,
RootId = profile.rootDnaId,
Root = profile.root,
PosType = profile.posTypeName,
PosLevel = profile.posLevelName
}))
//.Where(x =>
// x.citizenId != null && profile.Any(p => p.CitizenId == x.citizenId))
.Where(x => req.node == 4 ? x.Child4Id == req.nodeId : (req.node == 3 ? x.Child3Id == req.nodeId : (req.node == 2 ? x.Child2Id == req.nodeId : (req.node == 1 ? x.Child1Id == req.nodeId : (req.node == 0 ? x.RootId == req.nodeId : (req.node == null ? true : true))))))
.Where(x => jsonData["result"] == "OWNER" || jsonData["result"] == "CHILD" ? true : (req.node == 0 ? x.Child1Id == null : (req.node == 1 ? x.Child2Id == null : (req.node == 2 ? x.Child3Id == null : (req.node == 3 ? x.Child4Id == null : true)))))
.Where(x => string.IsNullOrEmpty(req.posType) || x.PosType == req.posType)
.Where(x => string.IsNullOrEmpty(req.posLevel) || x.PosLevel == req.posLevel)
.Where(x => req.node == 4 ? x.Child4Id == req.nodeId : (req.node == 3 ? x.Child3Id == req.nodeId : (req.node == 2 ? x.Child2Id == req.nodeId : (req.node == 1 ? x.Child1Id == req.nodeId : (req.node == 0 ? x.RootId == req.nodeId : (req.node == null ? true : true))))))
.Where(x => jsonData["result"] == "OWNER" || jsonData["result"] == "CHILD" ? true : (req.node == 0 ? x.Child1Id == null : (req.node == 1 ? x.Child2Id == null : (req.node == 2 ? x.Child3Id == null : (req.node == 3 ? x.Child4Id == null : true)))))
.Where(x => string.IsNullOrEmpty(req.posType) || x.PosType == req.posType)
.Where(x => string.IsNullOrEmpty(req.posLevel) || x.PosLevel == req.posLevel)
.OrderByDescending(x => x.CreatedAt)
.ToList();
var groupedResult3 = mapData3
.GroupBy(x => x.fullName)
.Select(g => new
{
one = 0,
two = 0,
three = g.Count(), // Count of records per fullName
g.Where(x => x.fullName != null || x.fullName != "").FirstOrDefault()?.fullName,
g.Where(x => x.citizenId != null || x.citizenId != "").FirstOrDefault()?.citizenId,
g.Where(x => x.position != null || x.position != "").FirstOrDefault()?.position,
g.Where(x => x.posLevel != null || x.posLevel != "").FirstOrDefault()?.posLevel,
oc = (g.Where(x => x.Child4 != null || x.Child4 != "").FirstOrDefault()?.Child4 == null ? "" : g.Where(x => x.Child4 != null || x.Child4 != "").FirstOrDefault()?.Child4 + "\n") +
(g.Where(x => x.Child3 != null || x.Child3 != "").FirstOrDefault()?.Child3 == null ? "" : g.Where(x => x.Child3 != null || x.Child3 != "").FirstOrDefault()?.Child3 + "\n") +
(g.Where(x => x.Child2 != null || x.Child2 != "").FirstOrDefault()?.Child2 == null ? "" : g.Where(x => x.Child2 != null || x.Child2 != "").FirstOrDefault()?.Child2 + "\n") +
(g.Where(x => x.Child1 != null || x.Child1 != "").FirstOrDefault()?.Child1 == null ? "" : g.Where(x => x.Child1 != null || x.Child1 != "").FirstOrDefault()?.Child1 + "\n") +
(g.Where(x => x.Root != null || x.Root != "").FirstOrDefault()?.Root == null ? "" : g.Where(x => x.Root != null || x.Root != "").FirstOrDefault()?.Root),
g.Where(x => x.offense != null || x.offense != "").FirstOrDefault()?.offense,
g.Where(x => x.faultLevel != null || x.faultLevel != "").FirstOrDefault()?.faultLevel,
})
.ToList();
var resultSum = groupedResult1.Concat(groupedResult2).Concat(groupedResult3).ToArray();
var groupedResult = resultSum
.GroupBy(x => x.fullName)
.Select(g => new
{
// g.Where(x => x.no != null || x.no != "").FirstOrDefault()?.no,
g.Where(x => x.fullName != null || x.fullName != "").FirstOrDefault()?.fullName,
g.Where(x => x.citizenId != null || x.citizenId != "").FirstOrDefault()?.citizenId,
g.Where(x => x.position != null || x.position != "").FirstOrDefault()?.position,
g.Where(x => x.posLevel != null || x.posLevel != "").FirstOrDefault()?.posLevel,
g.Where(x => x.oc != null || x.oc != "").FirstOrDefault()?.oc,
g.Where(x => x.offense != null || x.offense != "").FirstOrDefault()?.offense,
g.Where(x => x.faultLevel != null || x.faultLevel != "").FirstOrDefault()?.faultLevel,
one = g.Sum(x => x.one), // Replace `score` with actual field name
two = g.Sum(x => x.two), // Replace `score` with actual field name
three = g.Sum(x => x.three), // Replace `score` with actual field name
})
.OrderBy(x => x.citizenId)
.ToList();
var resultMap = new List<dynamic>();
var count = 1;
var employees = new List<dynamic>();
foreach (var p in mapData)
foreach (var p in groupedResult)
{
var emp = new
{
@ -155,21 +320,16 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
citizenId = p.citizenId,
position = p.position,
posLevel = p.posLevel,
oc = (p.Child4 == null ? "" : p.Child4 + "\n") +
(p.Child3 == null ? "" : p.Child3 + "\n") +
(p.Child2 == null ? "" : p.Child2 + "\n") +
(p.Child1 == null ? "" : p.Child1 + "\n") +
(p.Root == null ? "" : p.Root),
oc = p.oc,
offense = p.offense,
faultLevel = p.faultLevel,
one = 0,
two = 0,
three = 0,
one = p.one,
two = p.two,
three = p.three,
};
employees.Add(emp);
resultMap.Add(emp);
count++;
}
var result = new
{
template = "reportDiscipline",
@ -178,7 +338,7 @@ namespace BMA.EHR.DisciplineSuspend.Service.Controllers
{
year = (req.year + 543).ToString().ToThaiNumber(),
dateCurrent = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}",
data = employees
data = resultMap
}
};
return Success(result);

View file

@ -0,0 +1,86 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
{
/// <inheritdoc />
public partial class update_table_disciplineresult_add_remark : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "DocumentRejectId",
table: "DisciplineInvestigate_ProfileComplaints",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci");
migrationBuilder.AddColumn<string>(
name: "RemarkReject",
table: "DisciplineInvestigate_ProfileComplaints",
type: "longtext",
nullable: true,
comment: "หมายเหตุยุติเรื่อง")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "Offense",
table: "DisciplineDisciplinary_ProfileComplaintInvestigates",
type: "longtext",
nullable: true,
comment: "ฐานความผิดรายบุคคล")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "Remark",
table: "DisciplineDisciplinary_ProfileComplaintInvestigates",
type: "longtext",
nullable: true,
comment: "ฐานความผิดรายบุคคลหมายเหตุ")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_DisciplineInvestigate_ProfileComplaints_DocumentRejectId",
table: "DisciplineInvestigate_ProfileComplaints",
column: "DocumentRejectId");
migrationBuilder.AddForeignKey(
name: "FK_DisciplineInvestigate_ProfileComplaints_Documents_DocumentRe~",
table: "DisciplineInvestigate_ProfileComplaints",
column: "DocumentRejectId",
principalTable: "Documents",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_DisciplineInvestigate_ProfileComplaints_Documents_DocumentRe~",
table: "DisciplineInvestigate_ProfileComplaints");
migrationBuilder.DropIndex(
name: "IX_DisciplineInvestigate_ProfileComplaints_DocumentRejectId",
table: "DisciplineInvestigate_ProfileComplaints");
migrationBuilder.DropColumn(
name: "DocumentRejectId",
table: "DisciplineInvestigate_ProfileComplaints");
migrationBuilder.DropColumn(
name: "RemarkReject",
table: "DisciplineInvestigate_ProfileComplaints");
migrationBuilder.DropColumn(
name: "Offense",
table: "DisciplineDisciplinary_ProfileComplaintInvestigates");
migrationBuilder.DropColumn(
name: "Remark",
table: "DisciplineDisciplinary_ProfileComplaintInvestigates");
}
}
}

View file

@ -1851,6 +1851,10 @@ namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
.HasColumnOrder(102)
.HasComment("แก้ไขข้อมูลล่าสุดเมื่อ");
b.Property<string>("Offense")
.HasColumnType("longtext")
.HasComment("ฐานความผิดรายบุคคล");
b.Property<string>("Organization")
.HasColumnType("longtext")
.HasComment("สังกัด");
@ -1871,6 +1875,10 @@ namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
.HasColumnType("longtext")
.HasComment("คำนำหน้า");
b.Property<string>("Remark")
.HasColumnType("longtext")
.HasComment("ฐานความผิดรายบุคคลหมายเหตุ");
b.Property<double?>("Salary")
.HasColumnType("double")
.HasComment("เงินเดือน");
@ -2531,6 +2539,9 @@ namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
b.Property<Guid>("DisciplineInvestigateId")
.HasColumnType("char(36)");
b.Property<Guid?>("DocumentRejectId")
.HasColumnType("char(36)");
b.Property<string>("FirstName")
.IsRequired()
.HasMaxLength(100)
@ -2594,6 +2605,10 @@ namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
.HasColumnType("longtext")
.HasComment("คำนำหน้า");
b.Property<string>("RemarkReject")
.HasColumnType("longtext")
.HasComment("หมายเหตุยุติเรื่อง");
b.Property<double?>("Salary")
.HasColumnType("double")
.HasComment("เงินเดือน");
@ -2706,6 +2721,8 @@ namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
b.HasIndex("DisciplineInvestigateId");
b.HasIndex("DocumentRejectId");
b.ToTable("DisciplineInvestigate_ProfileComplaints");
});
@ -3487,7 +3504,13 @@ namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BMA.EHR.Domain.Models.Discipline.Document", "DocumentReject")
.WithMany()
.HasForeignKey("DocumentRejectId");
b.Navigation("DisciplineInvestigate");
b.Navigation("DocumentReject");
});
modelBuilder.Entity("BMA.EHR.Domain.Models.Discipline.DisciplineReport_Profile", b =>