report placement, retire
This commit is contained in:
parent
1b04e2dfc3
commit
082f4b2f59
6 changed files with 984 additions and 29 deletions
|
|
@ -2773,15 +2773,285 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
[HttpGet("report1")]
|
[HttpGet("report1")]
|
||||||
public async Task<ActionResult<ResponseObject>> report1(string? nodeId = null, int? node = 0, DateOnly? startDate = null, DateOnly? startEnd = null)
|
public async Task<ActionResult<ResponseObject>> report1(string nodeId = "", int? node = null, DateTime? startDate = null, DateTime? endDate = null)
|
||||||
{
|
{
|
||||||
var data = new
|
var apiUrl = $"{_configuration["API"]}/org/find/node-all";
|
||||||
|
var data = new object();
|
||||||
|
var data1 = new List<dynamic>();
|
||||||
|
var data2 = new List<dynamic>();
|
||||||
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
template = "placement01",
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
reportName = "xlsx-report",
|
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
||||||
data = ""
|
var _res = await client.PostAsJsonAsync(apiUrl, new
|
||||||
};
|
{
|
||||||
|
node,
|
||||||
|
nodeId,
|
||||||
|
});
|
||||||
|
var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
var orgs = JsonConvert.DeserializeObject<NodeAllRequest>(_result);
|
||||||
|
|
||||||
|
if (orgs == null || orgs.result == null)
|
||||||
|
return Error("ไม่พบหน่วยงานนี้ในระบบ", 404);
|
||||||
|
|
||||||
|
int no = 1;
|
||||||
|
|
||||||
|
foreach (var item in orgs.result.isRootTrue)
|
||||||
|
{
|
||||||
|
var placementProfiles = _context.PlacementProfiles
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootId.Contains(item.rootId) &&
|
||||||
|
x.PlacementStatus.Trim().ToUpper() == "DONE")
|
||||||
|
.GroupBy(x => x.typeCommand.Trim().ToUpper())
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
TypeCommand = g.Key,
|
||||||
|
Count = g.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var placementAppointments = _context.PlacementAppointments
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.type.Trim().ToUpper() == "OFFICER")
|
||||||
|
.GroupBy(x => x.typeCommand.Trim().ToUpper())
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
TypeCommand = g.Key,
|
||||||
|
Count = g.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var pt_count = _context.PlacementTransfers
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
var pr_count = _context.PlacementReceives
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
var po_count = _context.PlacementOfficers
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
var prp_count = _context.PlacementRepatriations
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
var ro_count = _context.RetirementOthers
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
var pp_appoint = placementProfiles.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0;
|
||||||
|
var pp_slip = placementProfiles.FirstOrDefault(x => x.TypeCommand == "SLIP")?.Count ?? 0;
|
||||||
|
var pp_move = placementProfiles.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0;
|
||||||
|
|
||||||
|
var pa_appoint = placementAppointments.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0;
|
||||||
|
var pa_slip = placementAppointments.FirstOrDefault(x => x.TypeCommand == "SLIP")?.Count ?? 0;
|
||||||
|
var pa_move = placementAppointments.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0;
|
||||||
|
|
||||||
|
data1.Add(new
|
||||||
|
{
|
||||||
|
no = no,
|
||||||
|
rootName = item.name,
|
||||||
|
pp_appoint = pp_appoint,
|
||||||
|
pp_slip = pp_slip,
|
||||||
|
pp_move = pp_move,
|
||||||
|
pa_appoint = pa_appoint,
|
||||||
|
pa_slip = pa_slip,
|
||||||
|
pa_move = pa_move,
|
||||||
|
pt_count = pt_count,
|
||||||
|
pr_count = pr_count,
|
||||||
|
po_count = po_count,
|
||||||
|
prp_count = prp_count,
|
||||||
|
ro_count = ro_count,
|
||||||
|
total = (pp_appoint + pp_slip + pp_move + pa_appoint + pa_slip + pa_move + pt_count + pr_count + po_count + prp_count + ro_count)
|
||||||
|
});
|
||||||
|
no++;
|
||||||
|
}
|
||||||
|
no = 1;
|
||||||
|
foreach (var item in orgs.result.isRootFalse)
|
||||||
|
{
|
||||||
|
var placementProfiles = _context.PlacementProfiles
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootId.Contains(item.rootId) &&
|
||||||
|
x.PlacementStatus.Trim().ToUpper() == "DONE")
|
||||||
|
.GroupBy(x => x.typeCommand.Trim().ToUpper())
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
TypeCommand = g.Key,
|
||||||
|
Count = g.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var placementAppointments = _context.PlacementAppointments
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.type.Trim().ToUpper() == "OFFICER")
|
||||||
|
.GroupBy(x => x.typeCommand.Trim().ToUpper())
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
TypeCommand = g.Key,
|
||||||
|
Count = g.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var pt_count = _context.PlacementTransfers
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
var pr_count = _context.PlacementReceives
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
var po_count = _context.PlacementOfficers
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
var prp_count = _context.PlacementRepatriations
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
var ro_count = _context.RetirementOthers
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
var pp_appoint = placementProfiles.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0;
|
||||||
|
var pp_slip = placementProfiles.FirstOrDefault(x => x.TypeCommand == "SLIP")?.Count ?? 0;
|
||||||
|
var pp_move = placementProfiles.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0;
|
||||||
|
|
||||||
|
var pa_appoint = placementAppointments.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0;
|
||||||
|
var pa_slip = placementAppointments.FirstOrDefault(x => x.TypeCommand == "SLIP")?.Count ?? 0;
|
||||||
|
var pa_move = placementAppointments.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0;
|
||||||
|
|
||||||
|
data2 .Add(new
|
||||||
|
{
|
||||||
|
no = no,
|
||||||
|
rootName = item.name,
|
||||||
|
pp_appoint = pp_appoint,
|
||||||
|
pp_slip = pp_slip,
|
||||||
|
pp_move = pp_move,
|
||||||
|
pa_appoint = pa_appoint,
|
||||||
|
pa_slip = pa_slip,
|
||||||
|
pa_move = pa_move,
|
||||||
|
pt_count = pt_count,
|
||||||
|
pr_count = pr_count,
|
||||||
|
po_count = po_count,
|
||||||
|
prp_count = prp_count,
|
||||||
|
ro_count = ro_count,
|
||||||
|
total = (pp_appoint + pp_slip + pp_move + pa_appoint + pa_slip + pa_move + pt_count + pr_count + po_count + prp_count + ro_count)
|
||||||
|
});
|
||||||
|
no++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data = new
|
||||||
|
{
|
||||||
|
template = "reportPlacement01All",
|
||||||
|
reportName = "xlsx-report",
|
||||||
|
data = new
|
||||||
|
{
|
||||||
|
date = $"ตั้งแต่วันที่ {startDate.Value.Date.ToThaiShortDate().ToThaiNumber()} ถึง {endDate.Value.Date.ToThaiShortDate().ToThaiNumber()}",
|
||||||
|
dateCurrent = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}",
|
||||||
|
data1,
|
||||||
|
data1Count = new
|
||||||
|
{
|
||||||
|
pp_appoint = data1.Where(x => x.pp_appoint > 0).Sum(x => x.pp_appoint),
|
||||||
|
pp_slip = data1.Where(x => x.pp_slip > 0).Sum(x => x.pp_slip),
|
||||||
|
pp_move = data1.Where(x => x.pp_move > 0).Sum(x => x.pp_move),
|
||||||
|
pa_appoint = data1.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint),
|
||||||
|
pa_slip = data1.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip),
|
||||||
|
pa_move = data1.Where(x => x.pa_move > 0).Sum(x => x.pa_move),
|
||||||
|
pt_count = data1.Where(x => x.pt_count > 0).Sum(x => x.pt_count),
|
||||||
|
pr_count = data1.Where(x => x.pr_count > 0).Sum(x => x.pr_count),
|
||||||
|
po_count = data1.Where(x => x.po_count > 0).Sum(x => x.po_count),
|
||||||
|
prp_count = data1.Where(x => x.prp_count > 0).Sum(x => x.prp_count),
|
||||||
|
ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
||||||
|
total = data1.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
},
|
||||||
|
data2,
|
||||||
|
data2Count = new
|
||||||
|
{
|
||||||
|
pp_appoint = data2.Where(x => x.pp_appoint > 0).Sum(x => x.pp_appoint),
|
||||||
|
pp_slip = data2.Where(x => x.pp_slip > 0).Sum(x => x.pp_slip),
|
||||||
|
pp_move = data2.Where(x => x.pp_move > 0).Sum(x => x.pp_move),
|
||||||
|
pa_appoint = data2.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint),
|
||||||
|
pa_slip = data2.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip),
|
||||||
|
pa_move = data2.Where(x => x.pa_move > 0).Sum(x => x.pa_move),
|
||||||
|
pt_count = data2.Where(x => x.pt_count > 0).Sum(x => x.pt_count),
|
||||||
|
pr_count = data2.Where(x => x.pr_count > 0).Sum(x => x.pr_count),
|
||||||
|
po_count = data2.Where(x => x.po_count > 0).Sum(x => x.po_count),
|
||||||
|
prp_count = data2.Where(x => x.prp_count > 0).Sum(x => x.prp_count),
|
||||||
|
ro_count = data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
||||||
|
total = data2.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
},
|
||||||
|
sum = new
|
||||||
|
{
|
||||||
|
pp_appoint = data1.Where(x => x.pp_appoint > 0).Sum(x => x.pp_appoint) + data2.Where(x => x.pp_appoint > 0).Sum(x => x.pp_appoint),
|
||||||
|
pp_slip = data1.Where(x => x.pp_slip > 0).Sum(x => x.pp_slip) + data2.Where(x => x.pp_slip > 0).Sum(x => x.pp_slip),
|
||||||
|
pp_move = data1.Where(x => x.pp_move > 0).Sum(x => x.pp_move) + data2.Where(x => x.pp_move > 0).Sum(x => x.pp_move),
|
||||||
|
pa_appoint = data1.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint) + data2.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint),
|
||||||
|
pa_slip = data1.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip) + data2.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip),
|
||||||
|
pa_move = data1.Where(x => x.pa_move > 0).Sum(x => x.pa_move) + data2.Where(x => x.pa_move > 0).Sum(x => x.pa_move),
|
||||||
|
pt_count = data1.Where(x => x.pt_count > 0).Sum(x => x.pt_count) + data2.Where(x => x.pt_count > 0).Sum(x => x.pt_count),
|
||||||
|
pr_count = data1.Where(x => x.pr_count > 0).Sum(x => x.pr_count) + data2.Where(x => x.pr_count > 0).Sum(x => x.pr_count),
|
||||||
|
po_count = data1.Where(x => x.po_count > 0).Sum(x => x.po_count) + data2.Where(x => x.po_count > 0).Sum(x => x.po_count),
|
||||||
|
prp_count = data1.Where(x => x.prp_count > 0).Sum(x => x.prp_count) + data2.Where(x => x.prp_count > 0).Sum(x => x.prp_count),
|
||||||
|
ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count) + data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
||||||
|
total = data1.Where(x => x.total > 0).Sum(x => x.total) + data2.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
return Success(data);
|
return Success(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2794,17 +3064,129 @@ namespace BMA.EHR.Placement.Service.Controllers
|
||||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
[HttpGet("report2")]
|
[HttpGet("report2")]
|
||||||
public async Task<ActionResult<ResponseObject>> report2(string? nodeId = null, int? node = 0, DateOnly? startDate = null, DateOnly? startEnd = null)
|
public async Task<ActionResult<ResponseObject>> report2(string nodeId = "", int? node = null, DateTime? startDate = null, DateTime? endDate = null)
|
||||||
{
|
{
|
||||||
|
var apiUrl = $"{_configuration["API"]}/org/find/node-all";
|
||||||
var data = new
|
var data = new object();
|
||||||
|
var data1 = new List<dynamic>();
|
||||||
|
var data2 = new List<dynamic>();
|
||||||
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
template = "placement02",
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
||||||
|
var _res = await client.PostAsJsonAsync(apiUrl, new
|
||||||
|
{
|
||||||
|
node,
|
||||||
|
nodeId,
|
||||||
|
});
|
||||||
|
var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
var orgs = JsonConvert.DeserializeObject<NodeAllRequest>(_result);
|
||||||
|
|
||||||
|
if (orgs == null || orgs.result == null)
|
||||||
|
return Error("ไม่พบหน่วยงานนี้ในระบบ", 404);
|
||||||
|
|
||||||
|
int no = 1;
|
||||||
|
|
||||||
|
foreach (var item in orgs.result.isRootTrue)
|
||||||
|
{
|
||||||
|
var placementAppointments = _context.PlacementAppointments
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.type.Trim().ToUpper() == "OFFICER")
|
||||||
|
.GroupBy(x => x.typeCommand.Trim().ToUpper())
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
TypeCommand = g.Key,
|
||||||
|
Count = g.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var pa_appoint = placementAppointments.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0;
|
||||||
|
var pa_slip = placementAppointments.FirstOrDefault(x => x.TypeCommand == "SLIP")?.Count ?? 0;
|
||||||
|
var pa_move = placementAppointments.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0;
|
||||||
|
|
||||||
|
data1.Add(new
|
||||||
|
{
|
||||||
|
no = no,
|
||||||
|
rootName = item.name,
|
||||||
|
pa_appoint = pa_appoint,
|
||||||
|
pa_slip = pa_slip,
|
||||||
|
pa_move = pa_move,
|
||||||
|
total = (pa_appoint + pa_slip + pa_move)
|
||||||
|
});
|
||||||
|
no++;
|
||||||
|
}
|
||||||
|
no = 1;
|
||||||
|
foreach (var item in orgs.result.isRootFalse)
|
||||||
|
{
|
||||||
|
var placementAppointments = _context.PlacementAppointments
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootId.Contains(item.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.type.Trim().ToUpper() == "OFFICER")
|
||||||
|
.GroupBy(x => x.typeCommand.Trim().ToUpper())
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
TypeCommand = g.Key,
|
||||||
|
Count = g.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var pa_appoint = placementAppointments.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0;
|
||||||
|
var pa_slip = placementAppointments.FirstOrDefault(x => x.TypeCommand == "SLIP")?.Count ?? 0;
|
||||||
|
var pa_move = placementAppointments.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0;
|
||||||
|
|
||||||
|
data2.Add(new
|
||||||
|
{
|
||||||
|
no = no,
|
||||||
|
rootName = item.name,
|
||||||
|
pa_appoint = pa_appoint,
|
||||||
|
pa_slip = pa_slip,
|
||||||
|
pa_move = pa_move,
|
||||||
|
total = (pa_appoint + pa_slip + pa_move)
|
||||||
|
});
|
||||||
|
no++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data = new
|
||||||
|
{
|
||||||
|
template = "reportPlacement02All",
|
||||||
reportName = "xlsx-report",
|
reportName = "xlsx-report",
|
||||||
data = ""
|
data = new
|
||||||
|
{
|
||||||
|
date = $"ตั้งแต่วันที่ {startDate.Value.Date.ToThaiShortDate().ToThaiNumber()} ถึง {endDate.Value.Date.ToThaiShortDate().ToThaiNumber()}",
|
||||||
|
dateCurrent = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}",
|
||||||
|
data1,
|
||||||
|
data1Count = new
|
||||||
|
{
|
||||||
|
pa_appoint = data1.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint),
|
||||||
|
pa_slip = data1.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip),
|
||||||
|
pa_move = data1.Where(x => x.pa_move > 0).Sum(x => x.pa_move),
|
||||||
|
total = data1.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
},
|
||||||
|
data2,
|
||||||
|
data2Count = new
|
||||||
|
{
|
||||||
|
pa_appoint = data2.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint),
|
||||||
|
pa_slip = data2.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip),
|
||||||
|
pa_move = data2.Where(x => x.pa_move > 0).Sum(x => x.pa_move),
|
||||||
|
total = data2.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
},
|
||||||
|
sum = new
|
||||||
|
{
|
||||||
|
pa_appoint = data1.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint) + data2.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint),
|
||||||
|
pa_slip = data1.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip) + data2.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip),
|
||||||
|
pa_move = data1.Where(x => x.pa_move > 0).Sum(x => x.pa_move) + data2.Where(x => x.pa_move > 0).Sum(x => x.pa_move),
|
||||||
|
total = data1.Where(x => x.total > 0).Sum(x => x.total) + data2.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return Success(data);
|
return Success(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
BMA.EHR.Placement.Service/Requests/NodeAllRequest.cs
Normal file
24
BMA.EHR.Placement.Service/Requests/NodeAllRequest.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
using BMA.EHR.Domain.Models.MetaData;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace BMA.EHR.Placement.Service.Requests
|
||||||
|
{
|
||||||
|
public class NodeAllRequest
|
||||||
|
{
|
||||||
|
public NodeAllResult result { get; set; } = new();
|
||||||
|
}
|
||||||
|
public class NodeAllResult
|
||||||
|
{
|
||||||
|
public List<NodeAllRequestData> isRootTrue { get; set; } = new();
|
||||||
|
public List<NodeAllRequestData> isRootFalse { get; set; } = new();
|
||||||
|
}
|
||||||
|
public class NodeAllRequestData
|
||||||
|
{
|
||||||
|
public string? name { get; set; }
|
||||||
|
public string? rootId { get; set; }
|
||||||
|
public string? child1Id { get; set; }
|
||||||
|
public string? child2Id { get; set; }
|
||||||
|
public string? child3Id { get; set; }
|
||||||
|
public string? child4Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -33,7 +33,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly PermissionRepository _permission;
|
private readonly PermissionRepository _permission;
|
||||||
|
private readonly DisciplineDbContext _contextDiscipline;
|
||||||
public RetirementController(RetirementRepository repository,
|
public RetirementController(RetirementRepository repository,
|
||||||
NotificationRepository repositoryNoti,
|
NotificationRepository repositoryNoti,
|
||||||
ApplicationDBContext context,
|
ApplicationDBContext context,
|
||||||
|
|
@ -41,7 +41,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
OrganizationCommonRepository organizationCommonRepository,
|
OrganizationCommonRepository organizationCommonRepository,
|
||||||
IHttpContextAccessor httpContextAccessor,
|
IHttpContextAccessor httpContextAccessor,
|
||||||
PermissionRepository permission)
|
PermissionRepository permission,
|
||||||
|
DisciplineDbContext contextDiscipline)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
_repositoryNoti = repositoryNoti;
|
_repositoryNoti = repositoryNoti;
|
||||||
|
|
@ -51,6 +52,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_permission = permission;
|
_permission = permission;
|
||||||
|
_contextDiscipline = contextDiscipline;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region " Properties "
|
#region " Properties "
|
||||||
|
|
@ -1290,15 +1292,286 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
[HttpGet("report1")]
|
[HttpGet("report1")]
|
||||||
public async Task<ActionResult<ResponseObject>> report1(string? nodeId = null, int? node = 0, DateOnly? startDate = null, DateOnly? startEnd = null)
|
public async Task<ActionResult<ResponseObject>> report1(string nodeId = "", int? node = null, DateTime? startDate = null, DateTime? endDate = null)
|
||||||
{
|
{
|
||||||
var data = new
|
|
||||||
{
|
|
||||||
template = "retirement01",
|
|
||||||
reportName = "xlsx-report",
|
|
||||||
data = ""
|
|
||||||
};
|
|
||||||
|
|
||||||
|
var apiUrl = $"{_configuration["API"]}/org/find/node-all";
|
||||||
|
var data = new object();
|
||||||
|
var data1 = new List<dynamic>();
|
||||||
|
var data2 = new List<dynamic>();
|
||||||
|
|
||||||
|
using (var client = new HttpClient())
|
||||||
|
{
|
||||||
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
||||||
|
var _res = await client.PostAsJsonAsync(apiUrl, new
|
||||||
|
{
|
||||||
|
node,
|
||||||
|
nodeId
|
||||||
|
});
|
||||||
|
var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
var orgs = JsonConvert.DeserializeObject<NodeAllRequest>(_result);
|
||||||
|
|
||||||
|
if (orgs == null || orgs.result == null)
|
||||||
|
return Error("ไม่พบหน่วยงานนี้ในระบบ", 404);
|
||||||
|
|
||||||
|
int no = 1;
|
||||||
|
|
||||||
|
foreach (var org in orgs.result.isRootTrue)
|
||||||
|
{
|
||||||
|
//เกษียณ
|
||||||
|
var retire = _context.RetirementPeriods
|
||||||
|
.Include(x => x.RetirementProfiles.Where(x => x.rootId == org.rootId))
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Type.Trim().ToUpper() == "OFFICER")
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var rt_count = retire != null ? retire.RetirementProfiles.Count() : 0;
|
||||||
|
|
||||||
|
//ลาออก
|
||||||
|
var retirementResigns = _context.RetirementResigns
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId == org.rootId &&
|
||||||
|
x.IsCancel == false && x.Status == "DONE")
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var career_count = retirementResigns.Where(x => x.Reason == "CAREER").Count();
|
||||||
|
var move_count = retirementResigns.Where(x => x.Reason == "MOVE").Count();
|
||||||
|
var family_count = retirementResigns.Where(x => x.Reason == "FAMILY").Count();
|
||||||
|
var education_count = retirementResigns.Where(x => x.Reason == "EDUCATION").Count();
|
||||||
|
var other_count = retirementResigns.Where(x => x.Reason == "OTHER").Count();
|
||||||
|
|
||||||
|
//ขอโอน
|
||||||
|
var pt_count = _context.PlacementTransfers
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId.Contains(org.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ถึงแก่กรรม
|
||||||
|
var rd_count = _context.RetirementDeceaseds
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ให้ออก
|
||||||
|
var ro_count = _context.RetirementOuts
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.rootOldId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ปลดออก
|
||||||
|
var dl_cm19_count = _contextDiscipline.DisciplineDisciplinary_ProfileComplaintInvestigates
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.CommandTypeId == Guid.Parse("ef8db4d7-1472-4c1d-b73f-9114e618a96f") &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ไล่ออก
|
||||||
|
var dl_cm20_count = _contextDiscipline.DisciplineDisciplinary_ProfileComplaintInvestigates
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.CommandTypeId == Guid.Parse("d9dee5c3-b75a-4927-9ce2-51e2233cf20b") &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
data1.Add(new
|
||||||
|
{
|
||||||
|
no = no,
|
||||||
|
rootName = org.name,
|
||||||
|
rt_count,
|
||||||
|
career_count,
|
||||||
|
move_count,
|
||||||
|
family_count,
|
||||||
|
education_count,
|
||||||
|
other_count,
|
||||||
|
pt_count,
|
||||||
|
rd_count,
|
||||||
|
ro_count,
|
||||||
|
dl_cm19_count,
|
||||||
|
dl_cm20_count,
|
||||||
|
total = (rt_count + career_count + move_count + family_count + education_count + other_count + pt_count + rd_count + ro_count + dl_cm19_count + dl_cm20_count)
|
||||||
|
});
|
||||||
|
no++;
|
||||||
|
}
|
||||||
|
|
||||||
|
no = 1;
|
||||||
|
foreach (var org in orgs.result.isRootFalse)
|
||||||
|
{
|
||||||
|
//เกษียณ
|
||||||
|
var retire = _context.RetirementPeriods
|
||||||
|
.Include(x => x.RetirementProfiles.Where(x => x.rootId == org.rootId))
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Type.Trim().ToUpper() == "OFFICER")
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var rt_count = retire != null ? retire.RetirementProfiles.Count() : 0;
|
||||||
|
|
||||||
|
//ลาออก
|
||||||
|
var retirementResigns = _context.RetirementResigns
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId == org.rootId &&
|
||||||
|
x.IsCancel == false && x.Status == "DONE")
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var career_count = retirementResigns.Where(x => x.Reason == "CAREER").Count();
|
||||||
|
var move_count = retirementResigns.Where(x => x.Reason == "MOVE").Count();
|
||||||
|
var family_count = retirementResigns.Where(x => x.Reason == "FAMILY").Count();
|
||||||
|
var education_count = retirementResigns.Where(x => x.Reason == "EDUCATION").Count();
|
||||||
|
var other_count = retirementResigns.Where(x => x.Reason == "OTHER").Count();
|
||||||
|
|
||||||
|
//ขอโอน
|
||||||
|
var pt_count = _context.PlacementTransfers
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId.Contains(org.rootId) &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE")
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ถึงแก่กรรม
|
||||||
|
var rd_count = _context.RetirementDeceaseds
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ให้ออก
|
||||||
|
var ro_count = _context.RetirementOuts
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.rootOldId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ปลดออก
|
||||||
|
var dl_cm19_count = _contextDiscipline.DisciplineDisciplinary_ProfileComplaintInvestigates
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.CommandTypeId == Guid.Parse("ef8db4d7-1472-4c1d-b73f-9114e618a96f") &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ไล่ออก
|
||||||
|
var dl_cm20_count = _contextDiscipline.DisciplineDisciplinary_ProfileComplaintInvestigates
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.CommandTypeId == Guid.Parse("d9dee5c3-b75a-4927-9ce2-51e2233cf20b") &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
data2.Add(new
|
||||||
|
{
|
||||||
|
no = no,
|
||||||
|
rootName = org.name,
|
||||||
|
rt_count,
|
||||||
|
career_count,
|
||||||
|
move_count,
|
||||||
|
family_count,
|
||||||
|
education_count,
|
||||||
|
other_count,
|
||||||
|
pt_count,
|
||||||
|
rd_count,
|
||||||
|
ro_count,
|
||||||
|
dl_cm19_count,
|
||||||
|
dl_cm20_count,
|
||||||
|
total = (rt_count + career_count + move_count + family_count + education_count + other_count + pt_count + rd_count + ro_count + dl_cm19_count + dl_cm20_count)
|
||||||
|
});
|
||||||
|
no++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data = new
|
||||||
|
{
|
||||||
|
template = "reportRetirement01All",
|
||||||
|
reportName = "xlsx-report",
|
||||||
|
data = new
|
||||||
|
{
|
||||||
|
date = $"ตั้งแต่วันที่ {startDate.Value.Date.ToThaiShortDate().ToThaiNumber()} ถึง {endDate.Value.Date.ToThaiShortDate().ToThaiNumber()}",
|
||||||
|
dateCurrent = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}",
|
||||||
|
data1,
|
||||||
|
data1Count = new
|
||||||
|
{
|
||||||
|
rt_count = data1.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
||||||
|
career_count = data1.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
||||||
|
move_count = data1.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
||||||
|
family_count = data1.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
||||||
|
education_count = data1.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
||||||
|
other_count = data1.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
||||||
|
pt_count = data1.Where(x => x.pt_count > 0).Sum(x => x.pt_count),
|
||||||
|
rd_count = data1.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
||||||
|
ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
||||||
|
dl_cm19_count = data1.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
||||||
|
dl_cm20_count = data1.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
||||||
|
total = data1.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
},
|
||||||
|
data2,
|
||||||
|
data2Count = new
|
||||||
|
{
|
||||||
|
rt_count = data2.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
||||||
|
career_count = data2.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
||||||
|
move_count = data2.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
||||||
|
family_count = data2.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
||||||
|
education_count = data2.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
||||||
|
other_count = data2.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
||||||
|
pt_count = data2.Where(x => x.pt_count > 0).Sum(x => x.pt_count),
|
||||||
|
rd_count = data2.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
||||||
|
ro_count = data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
||||||
|
dl_cm19_count = data2.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
||||||
|
dl_cm20_count = data2.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
||||||
|
total = data2.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
},
|
||||||
|
sum = new
|
||||||
|
{
|
||||||
|
rt_count = data1.Where(x => x.rt_count > 0).Sum(x => x.rt_count) + data2.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
||||||
|
career_count = data1.Where(x => x.career_count > 0).Sum(x => x.career_count) + data2.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
||||||
|
move_count = data1.Where(x => x.move_count > 0).Sum(x => x.move_count) + data2.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
||||||
|
family_count = data1.Where(x => x.family_count > 0).Sum(x => x.family_count) + data2.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
||||||
|
education_count = data1.Where(x => x.education_count > 0).Sum(x => x.education_count) + data2.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
||||||
|
other_count = data1.Where(x => x.other_count > 0).Sum(x => x.other_count) + data2.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
||||||
|
pt_count = data1.Where(x => x.pt_count > 0).Sum(x => x.pt_count) + data2.Where(x => x.pt_count > 0).Sum(x => x.pt_count),
|
||||||
|
rd_count = data1.Where(x => x.rd_count > 0).Sum(x => x.rd_count) + data2.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
||||||
|
ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count) + data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
||||||
|
dl_cm19_count = data1.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count) + data2.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
||||||
|
dl_cm20_count = data1.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count) + data2.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
||||||
|
total = data1.Where(x => x.total > 0).Sum(x => x.total) + data2.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
return Success(data);
|
return Success(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1311,17 +1584,263 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
||||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
[HttpGet("report2")]
|
[HttpGet("report2")]
|
||||||
public async Task<ActionResult<ResponseObject>> report2(string? nodeId = null, int? node = 0, DateOnly? startDate = null, DateOnly? startEnd = null)
|
public async Task<ActionResult<ResponseObject>> report2(string nodeId = "", int? node = null, DateTime? startDate = null, DateTime? endDate = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
var data = new
|
var apiUrl = $"{_configuration["API"]}/org/find/node-all";
|
||||||
|
var data = new object();
|
||||||
|
var data1 = new List<dynamic>();
|
||||||
|
var data2 = new List<dynamic>();
|
||||||
|
|
||||||
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
template = "retirement02",
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||||
|
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
||||||
|
var _res = await client.PostAsJsonAsync(apiUrl, new
|
||||||
|
{
|
||||||
|
node,
|
||||||
|
nodeId
|
||||||
|
});
|
||||||
|
var _result = await _res.Content.ReadAsStringAsync();
|
||||||
|
var orgs = JsonConvert.DeserializeObject<NodeAllRequest>(_result);
|
||||||
|
|
||||||
|
if (orgs == null || orgs.result == null)
|
||||||
|
return Error("ไม่พบหน่วยงานนี้ในระบบ", 404);
|
||||||
|
|
||||||
|
int no = 1;
|
||||||
|
|
||||||
|
foreach (var org in orgs.result.isRootTrue)
|
||||||
|
{
|
||||||
|
//เกษียณ
|
||||||
|
var retire = _context.RetirementPeriods
|
||||||
|
.Include(x => x.RetirementProfiles.Where(x => x.rootId == org.rootId))
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Type.Trim().ToUpper() == "OFFICER")
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var rt_count = retire != null ? retire.RetirementProfiles.Count() : 0;
|
||||||
|
|
||||||
|
//ลาออก
|
||||||
|
var retirementResigns = _context.RetirementResigns
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId == org.rootId &&
|
||||||
|
x.IsCancel == false && x.Status == "DONE")
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var career_count = retirementResigns.Where(x => x.Reason == "CAREER").Count();
|
||||||
|
var move_count = retirementResigns.Where(x => x.Reason == "MOVE").Count();
|
||||||
|
var family_count = retirementResigns.Where(x => x.Reason == "FAMILY").Count();
|
||||||
|
var education_count = retirementResigns.Where(x => x.Reason == "EDUCATION").Count();
|
||||||
|
var other_count = retirementResigns.Where(x => x.Reason == "OTHER").Count();
|
||||||
|
|
||||||
|
//ถึงแก่กรรม
|
||||||
|
var rd_count = _context.RetirementDeceaseds
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ให้ออก
|
||||||
|
var ro_count = _context.RetirementOuts
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.rootOldId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ปลดออก
|
||||||
|
var dl_cm19_count = _contextDiscipline.DisciplineDisciplinary_ProfileComplaintInvestigates
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.CommandTypeId == Guid.Parse("ef8db4d7-1472-4c1d-b73f-9114e618a96f") &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ไล่ออก
|
||||||
|
var dl_cm20_count = _contextDiscipline.DisciplineDisciplinary_ProfileComplaintInvestigates
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.CommandTypeId == Guid.Parse("d9dee5c3-b75a-4927-9ce2-51e2233cf20b") &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
data1.Add(new
|
||||||
|
{
|
||||||
|
no = no,
|
||||||
|
rootName = org.name,
|
||||||
|
rt_count,
|
||||||
|
career_count,
|
||||||
|
move_count,
|
||||||
|
family_count,
|
||||||
|
education_count,
|
||||||
|
other_count,
|
||||||
|
rd_count,
|
||||||
|
ro_count,
|
||||||
|
dl_cm19_count,
|
||||||
|
dl_cm20_count,
|
||||||
|
total = (rt_count + career_count + move_count + family_count + education_count + other_count + rd_count + ro_count + dl_cm19_count + dl_cm20_count)
|
||||||
|
});
|
||||||
|
no++;
|
||||||
|
}
|
||||||
|
|
||||||
|
no = 1;
|
||||||
|
foreach (var org in orgs.result.isRootFalse)
|
||||||
|
{
|
||||||
|
//เกษียณ
|
||||||
|
var retire = _context.RetirementPeriods
|
||||||
|
.Include(x => x.RetirementProfiles.Where(x => x.rootId == org.rootId))
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Type.Trim().ToUpper() == "OFFICER")
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
var rt_count = retire != null ? retire.RetirementProfiles.Count() : 0;
|
||||||
|
|
||||||
|
//ลาออก
|
||||||
|
var retirementResigns = _context.RetirementResigns
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.rootOldId == org.rootId &&
|
||||||
|
x.IsCancel == false && x.Status == "DONE")
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var career_count = retirementResigns.Where(x => x.Reason == "CAREER").Count();
|
||||||
|
var move_count = retirementResigns.Where(x => x.Reason == "MOVE").Count();
|
||||||
|
var family_count = retirementResigns.Where(x => x.Reason == "FAMILY").Count();
|
||||||
|
var education_count = retirementResigns.Where(x => x.Reason == "EDUCATION").Count();
|
||||||
|
var other_count = retirementResigns.Where(x => x.Reason == "OTHER").Count();
|
||||||
|
|
||||||
|
//ถึงแก่กรรม
|
||||||
|
var rd_count = _context.RetirementDeceaseds
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ให้ออก
|
||||||
|
var ro_count = _context.RetirementOuts
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.rootOldId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ปลดออก
|
||||||
|
var dl_cm19_count = _contextDiscipline.DisciplineDisciplinary_ProfileComplaintInvestigates
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.CommandTypeId == Guid.Parse("ef8db4d7-1472-4c1d-b73f-9114e618a96f") &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
//ไล่ออก
|
||||||
|
var dl_cm20_count = _contextDiscipline.DisciplineDisciplinary_ProfileComplaintInvestigates
|
||||||
|
.Where(x =>
|
||||||
|
x.CreatedAt.Date >= startDate &&
|
||||||
|
x.CreatedAt.Date <= endDate &&
|
||||||
|
x.Status.Trim().ToUpper() == "DONE" &&
|
||||||
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
||||||
|
x.CommandTypeId == Guid.Parse("d9dee5c3-b75a-4927-9ce2-51e2233cf20b") &&
|
||||||
|
x.rootId.Contains(org.rootId))
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
data2.Add(new
|
||||||
|
{
|
||||||
|
no = no,
|
||||||
|
rootName = org.name,
|
||||||
|
rt_count,
|
||||||
|
career_count,
|
||||||
|
move_count,
|
||||||
|
family_count,
|
||||||
|
education_count,
|
||||||
|
other_count,
|
||||||
|
rd_count,
|
||||||
|
ro_count,
|
||||||
|
dl_cm19_count,
|
||||||
|
dl_cm20_count,
|
||||||
|
total = (rt_count + career_count + move_count + family_count + education_count + other_count + rd_count + ro_count + dl_cm19_count + dl_cm20_count)
|
||||||
|
});
|
||||||
|
no++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data = new
|
||||||
|
{
|
||||||
|
template = "reportRetirement02All",
|
||||||
reportName = "xlsx-report",
|
reportName = "xlsx-report",
|
||||||
data = ""
|
data = new
|
||||||
|
{
|
||||||
|
date = $"ตั้งแต่วันที่ {startDate.Value.Date.ToThaiShortDate().ToThaiNumber()} ถึง {endDate.Value.Date.ToThaiShortDate().ToThaiNumber()}",
|
||||||
|
dateCurrent = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}",
|
||||||
|
data1,
|
||||||
|
data1Count = new
|
||||||
|
{
|
||||||
|
rt_count = data1.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
||||||
|
career_count = data1.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
||||||
|
move_count = data1.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
||||||
|
family_count = data1.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
||||||
|
education_count = data1.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
||||||
|
other_count = data1.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
||||||
|
rd_count = data1.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
||||||
|
ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
||||||
|
dl_cm19_count = data1.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
||||||
|
dl_cm20_count = data1.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
||||||
|
total = data1.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
},
|
||||||
|
data2,
|
||||||
|
data2Count = new
|
||||||
|
{
|
||||||
|
rt_count = data2.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
||||||
|
career_count = data2.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
||||||
|
move_count = data2.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
||||||
|
family_count = data2.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
||||||
|
education_count = data2.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
||||||
|
other_count = data2.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
||||||
|
rd_count = data2.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
||||||
|
ro_count = data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
||||||
|
dl_cm19_count = data2.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
||||||
|
dl_cm20_count = data2.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
||||||
|
total = data2.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
},
|
||||||
|
sum = new
|
||||||
|
{
|
||||||
|
rt_count = data1.Where(x => x.rt_count > 0).Sum(x => x.rt_count) + data2.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
||||||
|
career_count = data1.Where(x => x.career_count > 0).Sum(x => x.career_count) + data2.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
||||||
|
move_count = data1.Where(x => x.move_count > 0).Sum(x => x.move_count) + data2.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
||||||
|
family_count = data1.Where(x => x.family_count > 0).Sum(x => x.family_count) + data2.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
||||||
|
education_count = data1.Where(x => x.education_count > 0).Sum(x => x.education_count) + data2.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
||||||
|
other_count = data1.Where(x => x.other_count > 0).Sum(x => x.other_count) + data2.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
||||||
|
rd_count = data1.Where(x => x.rd_count > 0).Sum(x => x.rd_count) + data2.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
||||||
|
ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count) + data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
||||||
|
dl_cm19_count = data1.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count) + data2.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
||||||
|
dl_cm20_count = data1.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count) + data2.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
||||||
|
total = data1.Where(x => x.total > 0).Sum(x => x.total) + data2.Where(x => x.total > 0).Sum(x => x.total)
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return Success(data);
|
return Success(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,11 @@ var builder = WebApplication.CreateBuilder(args);
|
||||||
var defaultConnection = builder.Configuration.GetConnectionString("DefaultConnection");
|
var defaultConnection = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||||
builder.Services.AddDbContext<ApplicationDBContext>(options =>
|
builder.Services.AddDbContext<ApplicationDBContext>(options =>
|
||||||
options.UseMySql(defaultConnection, ServerVersion.AutoDetect(defaultConnection)));
|
options.UseMySql(defaultConnection, ServerVersion.AutoDetect(defaultConnection)));
|
||||||
|
// Register DisciplineDbContext
|
||||||
|
var disciplineConnection = builder.Configuration.GetConnectionString("DisciplineConnection");
|
||||||
|
builder.Services.AddDbContext<DisciplineDbContext>(options =>
|
||||||
|
options.UseMySql(disciplineConnection, ServerVersion.AutoDetect(disciplineConnection)));
|
||||||
|
|
||||||
builder.Services.AddHealthChecks();
|
builder.Services.AddHealthChecks();
|
||||||
// Add Hangfire services.
|
// Add Hangfire services.
|
||||||
builder.Services.AddHangfire(configuration => configuration
|
builder.Services.AddHangfire(configuration => configuration
|
||||||
|
|
|
||||||
24
BMA.EHR.Retirement.Service/Requests/NodeAllRequest.cs
Normal file
24
BMA.EHR.Retirement.Service/Requests/NodeAllRequest.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
using BMA.EHR.Domain.Models.MetaData;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace BMA.EHR.Retirement.Service.Requests
|
||||||
|
{
|
||||||
|
public class NodeAllRequest
|
||||||
|
{
|
||||||
|
public NodeAllResult result { get; set; } = new();
|
||||||
|
}
|
||||||
|
public class NodeAllResult
|
||||||
|
{
|
||||||
|
public List<NodeAllRequestData> isRootTrue { get; set; } = new();
|
||||||
|
public List<NodeAllRequestData> isRootFalse { get; set; } = new();
|
||||||
|
}
|
||||||
|
public class NodeAllRequestData
|
||||||
|
{
|
||||||
|
public string? name { get; set; }
|
||||||
|
public string? rootId { get; set; }
|
||||||
|
public string? child1Id { get; set; }
|
||||||
|
public string? child2Id { get; set; }
|
||||||
|
public string? child3Id { get; set; }
|
||||||
|
public string? child4Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,8 @@
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
//"DefaultConnection": "User Id=sys;Password=P@ssw0rd;DBA Privilege=SYSDBA;Data Source=localhost:1521/ORCLCDB",
|
//"DefaultConnection": "User Id=sys;Password=P@ssw0rd;DBA Privilege=SYSDBA;Data Source=localhost:1521/ORCLCDB",
|
||||||
// "DefaultConnection": "server=127.0.0.1;user=root;password=P@ssw0rd;port=3308;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
|
// "DefaultConnection": "server=127.0.0.1;user=root;password=P@ssw0rd;port=3308;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
|
||||||
"DefaultConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
|
"DefaultConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;",
|
||||||
|
"DisciplineConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_discipline_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
|
||||||
},
|
},
|
||||||
"Jwt": {
|
"Jwt": {
|
||||||
"Key": "HP-FnQMUj9msHMSD3T9HtdEnphAKoCJLEl85CIqROFI",
|
"Key": "HP-FnQMUj9msHMSD3T9HtdEnphAKoCJLEl85CIqROFI",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue